Home > DeveloperSection > Forums > “Remember me” functionality in a Login form
Takeshi Okada
Takeshi Okada

Total Post:89

Points:629
Posted on    December-16-2013 12:33 AM

 ASP.Net ASP.Net 
Ratings:


 1 Reply(s)
 1021  View(s)
Rate this:

I am using linq to entity connection. I want to keep user logged in once he entered into his account, This is my code. It's not working. Help, please

    if (this.ChkRememberme != null && this.ChkRememberme.Checked == true)

    {

        HttpCookie cookie = new HttpCookie(TxtUserName.Text, TxtPassword.Text);

        cookie.Expires.AddYears(1);

        Response.Cookies.Add(cookie);

    }



Pravesh Singh

Total Post:411

Points:2881
Posted on    December-16-2013 12:52 AM

Hi Takeshi,

Try this :

if (this.ChkRememberme != null && this.ChkRememberme.Checked == true)

    {

 int timeout = rememberMe ? 525600 : 30; // Timeout in minutes, 525600 = 365 days.

    var ticket = new FormsAuthenticationTicket(TxtUserName.Text, TxtPassword.Text);

    string encrypted = FormsAuthentication.Encrypt(ticket);

    var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted);

    cookie.Expires = System.DateTime.Now.AddMinutes(timeout);

    cookie.HttpOnly = true; // cookie not available in javascript.

    Response.Cookies.Add(cookie);

}


Don't want to miss updates? Please click the below button!

Follow MindStick