【发布时间】:2016-06-14 07:04:15
【问题描述】:
我正在开发 ASP.NET MVC5 应用程序,我想实现 RememberMe 功能。在这里,当用户检查 RememberMe 时,用户名应该自动获取到用户名字段,每当用户再次访问网站时。我尝试过以下方法。但它有问题,我无法做到这一点。谁能帮我做这件事?
var authTicket = new FormsAuthenticationTicket(
1,
userId, //user id
DateTime.Now,
DateTime.Now.AddMinutes(50), // expiry
model.RememberMe, //true to remember
string.Empty
);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(authTicket));
if (authTicket.IsPersistent)
{
cookie.Expires = authTicket.Expiration;
}
System.Web.HttpContext.Current.Response.Cookies.Add(cookie);
提前致谢。
【问题讨论】:
标签: asp.net asp.net-mvc authentication remember-me