我认为我的滑动过期没有发生,人们在几分钟后就不断退出。这是我的设置,为了测试目的,slidingExpiration 设置为“true”,超时我更新为“60”而不是 20。
<authentication mode="Forms">
<forms name="Lab.ASPXFORMSAUTH" loginUrl="~/Login" enableCrossAppRedirects="true" cookieless="AutoDetect" domain="lab.org" slidingExpiration="true" protection="All" path="/" timeout="60" />
</authentication>
这是登录代码。如果选择“记住我”,则票证到期时间将为西北一年后,否则将为从现在起 20 分钟。
private static void LoginUser(User user, bool isRememberMe)
{
//Forms Authentication
var expiryDateTime = isRememberMe ? DateTime.Now.AddYears(1) : DateTime.Now.AddMinutes(20);
var ticket = new FormsAuthenticationTicket(
1, // Ticket version
user.UserId, // Username associated with ticket
DateTime.Now, // Date/time issued
expiryDateTime, // Date/time to expire DateTime.Now.AddYears(1)
isRememberMe, // "true" for a persistent user cookie
JsonConvert.SerializeObject(user.Roles), // User-data, in this case the roles
FormsAuthentication.FormsCookiePath); // Path cookie valid for
// Encrypt the cookie using the machine key for secure transport
var hash = FormsAuthentication.Encrypt(ticket);
var cookie = new HttpCookie(
FormsAuthentication.FormsCookieName, // Name of auth cookie
hash); // Hashed ticket
// Set the cookie's expiration time to the tickets expiration time
if (ticket.IsPersistent)
{
cookie.Expires = ticket.Expiration;
}
// Add the cookie to the list for outgoing response
HttpContext.Current.Response.Cookies.Add(cookie);
}
看起来我的 web.config 和票证到期时间之间存在一些脱节。你看到我在这里做错了什么吗?谢谢
更新#1:
测试了开发站点,登录(FF 和 chrome),然后 5 分钟后刷新页面,它让我保持登录状态。然后 14 分钟后刷新页面,它将我重定向到登录页面。
测试了产品站点(2 个服务器 - 负载平衡),遵循开发站点刷新间隔,让我保持登录状态。
最佳答案
Scott Hanselman 在这里详细介绍了它。
http://www.hanselman.com/blog/WeirdTimeoutsWithCustomASPNETFormsAuthentication.aspx
您可能需要查看 iisidele 超时
https://technet.microsoft.com/en-us/library/cc771956%28v=ws.10%29.aspx
在 ASP.NET 论坛上寻求帮助来解决该问题。
关于asp.net - 表单例份验证 - 滑动过期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29035481/