我遇到了ASP.NET MVC的一个问题,它迫使用户在大约20分钟的非活动状态后重新登录。在ASP.NET MVC会话中存储自定义委托人的问题
我使用窗体身份验证,并增加在配置文件中的超时为:
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="9999999" />
</authentication>
我也设置在配置文件中的会话超时为:
<sessionState timeout="120"></sessionState>
我立足这一关罗克福德Lhotka的CSLA ASP.NET MVC例子,并已在我的Global.asax如下:
protected void Application_AcquireRequestState(object sender, EventArgs e)
{
if (HttpContext.Current.Handler is IRequiresSessionState)
{
if (Csla.ApplicationContext.AuthenticationType == "Windows")
return;
System.Security.Principal.IPrincipal principal;
try
{
principal = (System.Security.Principal.IPrincipal)
HttpContext.Current.Session[MyMembershipProvider.SESSION_KEY];
}
catch
{
principal = null;
}
if (principal == null)
{
if (this.User.Identity.IsAuthenticated && this.User.Identity is FormsIdentity)
{
// no principal in session, but ASP.NET token
// still valid - so sign out ASP.NET
FormsAuthentication.SignOut();
this.Response.Redirect(this.Request.Url.PathAndQuery);
}
// didn't get a principal from Session, so
// set it to an unauthenticted PTPrincipal
BusinessPrincipal.Logout();
}
else
{
// use the principal from Session
Csla.ApplicationContext.User = principal;
}
}
}
从我可以告诉它只应在120分钟不活动之后超时......但由于某种原因,它总是在闲置20分钟后超时。我知道为什么发生这种情况,有什么想法?
我正在倾销表单身份验证并通过会话自己处理它的想法,但我恐怕会失去[授权]属性等功能。试着不要走这条路。
是否可以将自定义主体对象存储为cookie?我只是不希望为每一个页面或动作验证/授权用户。
我正在失去头发......迅速! =)
这是一个伟大的观点!所以只是因为我在Cookie中和会话状态中设置了超时设置......应用程序池可能会尽快回收它?那可能吗? – mattruma 2010-03-04 18:19:10
无论如何要测试以查看哪些导致超时?我假设它是会议。 – mattruma 2010-03-04 18:20:06
@mattruma,据我所知,App Pool可能会更快地回收它。但我不知道如何测试它。 IIS7具有应用程序池的回收设置。也许你应该试试这个。 – 2010-03-04 18:25:03