“Remember me” functionality in a Login form

Total Post:89

Points:629
 1724  View(s)
Ratings:
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);
    }
  1. Post:412

    Points:2888
    Re: “Remember me” functionality in a Login form

    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);
    }

      Modified On Apr-03-2018 06:38:12 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!