2015-09-09 37 views
1

我有主站點及其子站點站點。重定向到來自子域名站點的請求的不同頁面

  • 當用戶進入主網站網址www.mysite.com當用戶輸入二級域名網站的網址sample.mysite.com它應該重定向到'Welcom.aspx'

爲了實現這一點,應該重定向到'Login.aspx'

  • 什麼最好的方法呢?

    • IIS設置中的更改?
    • 修改代碼在Global.asax
    • 重定向

    我有什麼代碼,如果我需要修改Global.asax中寫道:創建虛擬頁面?

  • 回答

    0

    爲了實現重定向,修改Global.asax中的代碼將是最好的一個

    1

    個人而言,我會選擇第二個選項,修改Global.asax文件。

    void Application_BeginRequest(Object source, EventArgs e) 
        { 
         string host = HttpContext.Current.Request.Url.Host.ToLower(); 
         if (host == "www.mysite.com") 
         { 
          //Incase if you are using any session 
          if (Session["User"] == null) 
           Response.Redirect("Login.aspx"); 
          else 
          { 
           //validate the session 
           Response.Redirect("Home.aspx"); 
          } 
         } 
         else if (host == "sample.mysite.com") 
         { 
          Response.Redirect("Welcome.aspx"); 
         } 
        } 
    
    +0

    'Application_BeginRequest'火災只有一次,而不是在每次請求 – Shaggy

    +0

    此事件在每個請求的**開始上調**爲Web應用程序。 – Chandru

    相關問題