我有一个带有身份验证表单的 MVC 3 应用程序。当用户选中“记住我”复选框时,auth cookie 必须设置为 2 周,如果没有,则应设置为 30 分钟。在这两种情况下,都应该打开滑动到期。根据这篇文章,我创建了以下方法,该方法创建了自定义身份验证 cookie:
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
1, //version
username,
DateTime.Now, //issue date
rememberMe ? DateTime.Now.AddDays(14) : DateTime.Now.AddMinutes(30), // exprie date
rememberMe, // is persistent
null
);
var ecnryptedTicket = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, ecnryptedTicket);
cookie.Expires = ticket.Expiration; // to expire cookie together with ticket
response.Cookies.Add(cookie);
之后如何以编程方式设置滑动到期?