2

当用户点击记住我时,如何创建一个 cookie 来存储用户名和密码?复选框。

4

1 回答 1

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");
}
于 2013-08-30T09:16:51.293 回答