0
我正在研究ASP.NET MVC5应用程序,并且我想实现RememberMe功能。在这里,当用户检查RememberMe时,每当用户再次访问网站时,用户名应该自动获取到用户名字段。我尝试了以下方法。但它有问题,我无法做到这一点。任何人都可以帮助我做到这一点?记住我 - 获取用户名 - MVC
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);
在此先感谢。