Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Persisitent authentication

Persisitent authentication

Scheduled Pinned Locked Moved ASP.NET
securityquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    realJSOP
    wrote on last edited by
    #1

    I'm using forms authentication on my site, and I want the login to be persistent (saved in a cookie?) for a number of days so that the user doesn't have to login each time he visits. Here's the code I use on my login page:

    if (membership.ValidateUser(this.username.Text, this.password.Text))
    {
    FormsAuthentication.Initialize();
    DateTime dtNow = DateTime.Now;
    FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, this.username.Text, dtNow, dtNow.AddMinutes(30), true, "user", FormsAuthentication.FormsCookiePath);
    string encryptedTicket = FormsAuthentication.Encrypt(ticket);
    Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket));
    Response.Redirect(FormsAuthentication.GetRedirectUrl(this.username.Text, true));
    }

    What am I doing wrong (or what am I missing)?

    "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
    -----
    "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

    F 1 Reply Last reply
    0
    • R realJSOP

      I'm using forms authentication on my site, and I want the login to be persistent (saved in a cookie?) for a number of days so that the user doesn't have to login each time he visits. Here's the code I use on my login page:

      if (membership.ValidateUser(this.username.Text, this.password.Text))
      {
      FormsAuthentication.Initialize();
      DateTime dtNow = DateTime.Now;
      FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, this.username.Text, dtNow, dtNow.AddMinutes(30), true, "user", FormsAuthentication.FormsCookiePath);
      string encryptedTicket = FormsAuthentication.Encrypt(ticket);
      Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket));
      Response.Redirect(FormsAuthentication.GetRedirectUrl(this.username.Text, true));
      }

      What am I doing wrong (or what am I missing)?

      "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
      -----
      "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

      F Offline
      F Offline
      Fred_Smith
      wrote on last edited by
      #2

      This may help: http://blogs.msdn.com/tmeston/archive/2003/07/24/10505.aspx[^]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups