【发布时间】:2012-11-13 22:39:05
【问题描述】:
有人可以向我解释一下 ASP.NET 表单身份验证的工作原理吗,因为我似乎不明白,而且我一直在退出。
就目前而言,我有用户名、密码和“保持登录”复选框。我将根据这些值创建票证和 cookie,如下所示:
// Create ticket
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,email,DateTime.UtcNow,DateTime.UtcNow.AddMinutes(30),remember,String.Empty);
// Encrypt ticket
string cookie_contents = FormsAuthentication.Encrypt(ticket);
// Create cookie
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName,cookie_contents);
if (remember) {
cookie.Expires = DateTime.UtcNow.AddDays(90);
}
cookie.Path = FormsAuthentication.FormsCookiePath;
cookie.Secure = true;
// Add cookie to response
Response.Cookies.Add(cookie);
我希望使用此代码登录我的网站并假设我选中“保持登录状态”并保持登录状态至少 90 天?
但是我看到的是,我在首次登录后至少 30 分钟被注销(这是为票预留的时间?)。
cookie 到期和票证到期之间有什么区别,以及如何让自己保持签名。我需要为 cookie 和票证都设置 90 天吗?
【问题讨论】: