2

How can i create a cookie that store the user name and password when user clicks remember me? check box.

Adrian Thompson Phillips
  • 6,893
  • 6
  • 38
  • 69
AJay Garg
  • 31
  • 1
  • 1
  • 8

1 Answers1

0

For Remember me functionality yours Action will go like this

[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");
}
Jatin patil
  • 4,252
  • 1
  • 18
  • 27
  • before you copy code from other places you should at least tell them where you got it from. In this case, just redirect to the source: http://stackoverflow.com/questions/5619791/implementing-remember-me-feature-in-asp-net-mvc – Adam Tuliper Aug 30 '13 at 18:47
  • Thanks bt It takes rememberMe value always false and rememberMe is not a property of class. – AJay Garg Sep 03 '13 at 12:05
  • You will have to add `rememberMe` to class. so while creating ticket the appropriate value will get set. – Jatin patil Sep 03 '13 at 12:08