Asp.net Visual Studio 2013中的会话管理?

Asp.net Visual Studio 2013中的会话管理?,asp.net,.net,visual-studio,session,session-timeout,Asp.net,.net,Visual Studio,Session,Session Timeout,我是asp.net的新开发人员。我想做一个会话管理,如果10分钟没有任何动作,系统将结束会话并注销用户 我搜索了一下,发现了以下代码: 在Web.config文件中: <sessionState mode="InProc" cookieless="true" timeout="10" /> 但是当我尝试它的时候,它不起作用! 我不知道我应该在服务器上而不是本地主机上尝试,或者这段代码不满足我需要的目的?在页面加载中尝试这一点 HttpContext.Current

我是asp.net的新开发人员。我想做一个会话管理,如果10分钟没有任何动作,系统将结束会话并注销用户

我搜索了一下,发现了以下代码:

在Web.config文件中:

<sessionState
   mode="InProc"
   cookieless="true"
   timeout="10" />
但是当我尝试它的时候,它不起作用! 我不知道我应该在服务器上而不是本地主机上尝试,或者这段代码不满足我需要的目的?

在页面加载中尝试这一点

HttpContext.Current.Session.Abandon();
HttpContext.Current.Response.Cookies.Clear();
Authentication.SignOut();
Response.Redirect("~/Login.aspx");
试一试

公共类PageBase:System.Web.UI.Page
{
受保护的覆盖无效OnPreRender(EventArgs e)
{
基于预渲染(e);
自动编辑();
}
public void AutoRedirect()
{
int_毫秒超时=(this.Session.Timeout*60000);
字符串str_Script=@”
intervalset=window.setInterval('Redirect()',“+int_毫秒激励.ToString()+@”);
函数重定向()
{
警报('您的会话已过期,系统立即重定向到登录页面。!\n\n');
window.location.href='/login.aspx';
}
";
RegisterClientScriptBlock(this.GetType(),“重定向”,str_脚本);
}
}
阅读更多


可能重复:请注意,会话过期不一定与身份验证有关。我应该为“authentication.SignOut();”包含哪些名称空间?使用FormsAuthentication并使用System.Web.Security添加名称空间;有用的链接!竖起大拇指。这是最好的答案。很抱歉,我不能投票支持你的答案,因为我的名声不好。谢谢:)
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);

}

}