2017-05-12 18 views
1

我正在使用母版頁處理asp.net webforms項目。我希望網站在會話結束時自動重定向到login.aspx頁面。我嘗試了以下鏈接給出的建議。 https://code.msdn.microsoft.com/Auto-redirect-to-login-e1782b2f 本質上,我已將JavaScript從鏈接複製到母版頁的aspx頭部分,並在母版頁的頁面加載事件中使用了C#代碼。但在設置3分鐘會話超時後,它不會重定向到登錄頁面。我在我的web.config文件中有以下條目。如何自動重定向到登錄頁面,當會話在具有母版頁的網站上過期

<sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" 
sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes" 
cookieless="false" timeout="3" /> 

我甚至嘗試通過這個鏈接建議的global.ascx頁面,這也沒有工作。 http://www.c-sharpcorner.com/UploadFile/0c1bb2/redirect-page-after-session-time-out-in-Asp-Net424/ 感謝

+0

有'身份驗證模式= 「表單」'在網頁的.config? –

+0

它有: Massey

+0

你試過像我的回答一樣執行嗎? –

回答

0

您可以在母版頁一樣檢查會話:

protected void Page_Load(object sender, EventArgs e) 
    { 
    if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated) 
    { 
     if (!IsPostBack) 
     { 
      //User session active 
     } 
    } 
    else 
    { 
     //User session not active 
     Response.Redirect("Login.aspx", false); 
    } 
} 

和更新Web.config文件,如:

<authentication mode="Forms"> 
    <forms loginUrl="~/Login.aspx" protection="All" timeout="3000" path="/" /> 
</authentication> 
相關問題