2014-02-19 29 views
-2

我用下面的Web配置代碼,但是當session期滿不工作properly.Suggest你的代碼重定向如何重定向頁面,當會話過期

我的代碼是:

<authentication mode="Forms"> 
     <forms name="MyAuth" timeout="60" protection="All" loginUrl="Login.aspx" slidingExpiration="true" /> 
    </authentication> 
    <sessionState mode="InProc" cookieless="false" timeout="60" /> 
+0

什麼是「無法正常工作」?什麼_does_發生? – CodeCaster

+0

可能重複[重定向到會話超時後登錄頁面](http://stackoverflow.com/questions/12502295/redirect-to-login-page-after-session-timeout) – CodeCaster

+0

@CodeCaster它會顯示錯誤時,當我嘗試在20分鐘後點擊一個按鈕 –

回答

0

我請使用以下代碼:

<authentication mode="Forms"> 
     <forms name="WhateverYourAuthNameIs" loginUrl="~/Login.aspx" defaultUrl="~/Default.aspx" protection="All" path="/" cookieless="AutoDetect" timeout="2880" /> 
</authentication> 

完全爲我工作。

0

您可以使用Session [「sessionName」]檢查會話,看它是否返回null,如果它只是使用Response.Redirect(「login.aspx」)重定向它們;

if(Session["sessionName"]==null) 
{ 
    Response.Redirect("Login.aspx"); 
} 
相關問題