Note that there are some explanatory texts on larger screens.

plurals
  1. POforms authentication cookie replacement
    primarykey
    data
    text
    <p>I have a problem with users being kicked out after the forms authentication ticket is renewed and the old one has expired. The first ticket i get when i signed in is:</p> <p>Ticket: A094D6F0401A5B6D97688198B09F17B03D209............ Ends: Thu, 28 Mar 2013 08:56:33 GMT</p> <p>And after some time the ticket is renewed and i get this cookie: (The cookie expire when the ticket is expire, so no problem there) </p> <p>Ticket: 215373E662852AD0CC540AC27F547787............. Ends: Thu, 28 Mar 2013 08:58:17 GMT</p> <p>This ticket is renewed by a javascript reloader in the background for the user. Now, if i update the page, i will be kicked out, why? When i renew the ticket i use this:</p> <pre><code> var Id = (FormsIdentity)HttpContext.Current.User.Identity; var Ticket = Id.Ticket; var NewAuthTicket = FormsAuthentication.RenewTicketIfOld(Ticket); HttpContext.Current.User = new System.Security.Principal.GenericPrincipal(new FormsIdentity(NewAuthTicket), new[] {""}); if (NewAuthTicket != null &amp;&amp; NewAuthTicket.Expiration &gt; Ticket.Expiration) { // Create the (encrypted) cookie. var ObjCookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(NewAuthTicket)) { HttpOnly = true, Expires = NewAuthTicket.Expiration, Secure = FormsAuthentication.RequireSSL }; // Add the cookie to the list for outbound response. HttpContext.Current.Response.Cookies.Add(ObjCookie); Ticket = NewAuthTicket; } </code></pre> <p>Is there any solution for this?</p> <p><em><strong>UPDATE:</em></strong></p> <p>When i set the cookie for the first time i use this:</p> <p>var ExpiryDate = !rememberMe ? DateTime.Now.AddMinutes(cookieTimeoutHour) : DateTime.Now.AddYears(1);</p> <pre><code> //create a new forms auth ticket var Ticket = new FormsAuthenticationTicket(2, ui.UserNr.ToString(CultureInfo.InvariantCulture), DateTime.Now, ExpiryDate, true, String.Empty); //encrypt the ticket var EncryptedTicket = FormsAuthentication.Encrypt(Ticket); //create a new authentication cookie - and set its expiration date var AuthenticationCookie = new HttpCookie(FormsAuthentication.FormsCookieName, EncryptedTicket) { Expires = Ticket.Expiration, HttpOnly = true, Secure = FormsAuthentication.RequireSSL }; Current.Response.Cookies.Add(AuthenticationCookie); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload