[英]Session timeout before given time
我正在使用Asp.Net MVC应用程序的表单身份验证,如下所示:
码
public void SignIn(string userName, bool isCookiePersistent)
{
FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, userName, DateTime.Now, DateTime.Now.AddDays(14),
createPersistentCookie, string.Empty);
HttpCookie authCookie = FormsAuthentication.GetAuthCookie(userName, isCookiePersistent);
if (authTicket.IsPersistent)
{
authCookie.Expires = authTicket.Expiration;
}
authCookie.Value = FormsAuthentication.Encrypt(authTicket);
HttpContext.Current.Response.Cookies.Add(authCookie);
}
public void SignOut()
{
FormsAuthentication.SignOut();
}
问题:问题是,如果我将表单身份验证超时设置为4小时,登录后半小时后我的用户仍然重定向到登录页面。
我已经尝试通过在Web.config中同时包含SessionSate
或不包含SessionState
进行操作,但是注意到正在发生。 问题仍然存在。 这是我下面的web.cofig代码。
Web.config(不带sessionState元素)
<authentication mode="Forms">
<forms loginUrl="~/LogOn/LogOn" requireSSL="false" timeout="240" defaultUrl="~/Home/Home" name="__appcookie" path="/" slidingExpiration="true" ticketCompatibilityMode="Framework40" protection="All">
</forms>
</authentication>
Web.config(带有sessionState元素)
<sessionState timeout="240"></sessionState>
<authentication mode="Forms">
<forms loginUrl="~/LogOn/LogOn" requireSSL="false" timeout="240" defaultUrl="~/Home/Home" name="__appcookie" path="/" slidingExpiration="true" ticketCompatibilityMode="Framework40" protection="All">
</forms>
</authentication>
有人可以告诉我,在web.config中包含sessionState
和sessionTimeout
真的很重要吗? 我不能仅formAuthentication
整个应用程序中使用formAuthentication
吗?
无论我是否使用sessionState
,即使仅使用form authentication
,我的用户在登录应用程序后半小时sessionState
重定向到登录页面。 (但是我已经将240分钟设置为form authentication timeout
)。
任何人都可以给我一些想法或解决方案。
提前致谢!
尝试在IIS中提高会话超时值。 该默认值是20分钟。 您可以将web.config设置为具有4年的会话超时,但是IIS会话超时将覆盖它。 假设您的用户在您的网站上未处于活动状态...
表单身份验证Cookie的默认时间是30分钟,这使我认为您的配置有问题。 您可以尝试简化配置以进行测试吗?
<authentication mode="Forms">
<forms loginUrl="~/LogOn/LogOn" timeout="240" protection="All" />
</authentication>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.