2017-05-10 20 views
0

我在我的網站上實施商店。選擇產品後,我將用戶重定向到銀行網址。當我調試發現銀行號碼後,購買銀行重定向用戶到我的網站重定向用戶到我的網站,因爲我把銀行中購買後用戶回來的斷點付諸行動。當用戶從其他網站重定向到本網站時,哪部分mvc項目被調用?

我把斷點放入Global.asax.csRegisterRoutes,但重定向到我的網站後,只稱爲特定動作。

我的推理是否正確?

我的測試是否正確?

+0

我不明白你爲什麼要使用global.asax事件?爲什麼不直接在mvc動作代碼中獲取查詢字符串值? –

回答

1

您可以使用Application_AcquireRequestState()事件Global.asax.cs

Application_AcquireRequestState() - 在爲客戶端檢索特定於會話的數據之前引發此事件並用於爲當前請求填充Session Collection。

例子:

protected void Application_AcquireRequestState(Object sender, EventArgs e) 
{ 
     bool redirected = false; 
     if (!redirected) 
     { 
      var routeData = urlHelper.RouteCollection.GetRouteData(currentContext); 
      if (routeData != null) 
      { 
       var action = routeData.Values["action"] as string; 
       var controller = routeData.Values["controller"] as string; 
       if (controller != null && controller.ToLower() != "login" && controller.ToLower() != "manage") 
       { 
        var baseUrl = "http://localhost/"+ "home/Index"; 
        Response.Redirect(baseUrl); 
       } 
      } 
      else{ 
       Response.Redirect("~/Home/index"); 
      } 

     } 

} 

你可以找到更多的信息形式thisthis鏈接。

希望它對您有所幫助。

+0

我使用數字銀行銷售產品。每個銀行將用戶重定向到另一個行動 – programmer138200

+0

您可以傳遞查詢參數。這是否足夠的答案?那麼不是簡單地解釋一下你真正想要的嗎?像什麼是'另一個行動' – Ashiquzzaman

+0

@ programmer138200我更新我的答案。 – Ashiquzzaman

相關問題