I have created login using asp .net MVC and I have added a cookie for users who select the "Remember me" option. Below is the code used to add a cookie
if (model.LoginViewModel.RememberMe)
{
var authTicket = new FormsAuthenticationTicket(
1,
model.LoginViewModel.Email,
DateTime.Now,
DateTime.Now.AddMinutes(20), // expiry
model.LoginViewModel.RememberMe, //true to remember
"",
"/");
//encrypt the ticket and add it to a cookie
HttpCookie cookie = new HttpCookie(
FormsAuthentication.FormsCookieName,
FormsAuthentication.Encrypt(authTicket));
Response.Cookies.Add(cookie);
}
and I have added this configuration to the web.config as well.
<authentication mode="Forms">
<forms loginUrl="~/candidate" timeout="2880" />
</authentication>
I still can't see my login details when I am going to login for the second time.
Do I have missed something here or are there any other way achieve this?
FormsAuthentication.SetAuthCookie(model.LoginViewModel.Email, model.LoginViewModel.RememberMe);will use the values you've assigned in the<forms />section.