如何在用户点击时记住我创建存储用户名和密码的cookie?复选框。
答案 0 :(得分:0)
为了记住我的功能你的行动会像这样
[HttpPost]
public ActionResult Login(LoginModel model) {
//Implementaion for authorization
.......
var authTicket = new FormsAuthenticationTicket(
1,
userId, //user id
DateTime.Now,
DateTime.Now.AddMinutes(20), // expiry
rememberMe, //boolean value true for remember
"", //roles
"/"
);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(authTicket));
Response.Cookies.Add(cookie);
return RedirectToAction("Index");
}