【发布时间】:2013-09-02 21:20:25
【问题描述】:
当用户点击记住我时,如何创建一个 cookie 来存储用户名和密码?复选框。
【问题讨论】:
标签: asp.net-mvc-3
当用户点击记住我时,如何创建一个 cookie 来存储用户名和密码?复选框。
【问题讨论】:
标签: asp.net-mvc-3
对于记住我的功能,你的操作将像这样进行
[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");
}
【讨论】:
rememberMe。因此,在创建票证时,将设置适当的值。