【发布时间】:2015-03-13 14:58:58
【问题描述】:
我认为我的滑动到期并没有发生,几分钟后人们就会不断退出。这是我的设置,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 分钟后刷新页面,它把我重定向到登录页面。
测试了 prod 站点(2 个服务器 - 负载平衡),遵循开发站点刷新间隔,让我保持登录状态。
【问题讨论】:
标签: asp.net asp.net-mvc forms-authentication