![](/img/trans.png)
[英]Session gets lost while debugging in visual studio 2013 web forms
[英]Session management in Visual Studio 2013?
我是asp.net的新開發人員。 我要進行會話管理,如果10分鍾過去而沒有任何操作,系統將結束會話並注銷用戶。
我搜索了一下,發現以下代碼:
在Web.config文件中:
<sessionState
mode="InProc"
cookieless="true"
timeout="10" />
在頁面中,我們要結束會話:
public int Timeout { get; set; }
但是當我嘗試時,它沒有用! 我不知道我應該在服務器而不是localhost中嘗試它,或者此代碼不能滿足我的目的?
在頁面加載中嘗試一下
HttpContext.Current.Session.Abandon();
HttpContext.Current.Response.Cookies.Clear();
Authentication.SignOut();
Response.Redirect("~/Login.aspx");
嘗試
public class PageBase : System.Web.UI.Page
{
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
AutoRedirect();
}
public void AutoRedirect()
{
int int_MilliSecondsTimeOut = (this.Session.Timeout * 60000);
string str_Script = @"
<script type='text/javascript'>
intervalset = window.setInterval('Redirect()'," + int_MilliSecondsTimeOut.ToString() + @");
function Redirect()
{
alert('Your session has been expired and system redirects to login page now.!\n\n');
window.location.href='/login.aspx';
}
</script>";
ClientScript.RegisterClientScriptBlock(this.GetType(), "Redirect", str_Script);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.