“Remember me” functionality in a Login form

Total Post:89


 1941  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);
  1. 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.

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


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.