I'm trying to get my head round the purpose of the isPersistent property found on the FormsAuthenticationTicket class. http://msdn.microsoft.com/en-us/library/kybcs83h.aspx
- Are there scenarios when setting isPersistent works?
- In what scenarios would I want to set
isPersistentto true and false?
The property seems to be redundant since I've found the only way for me to persist my users authentication cookie across browser sessions is to set the Expires property of the cookie created following ticket creation; even if the tickets isPersistent value is set to false.
I also found that setting the tickets expiry (not the cookie) to something like 10 seconds with isPersistent set to true has little effect; the ticket expires after 10 seconds.
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,
identity.Name,
DateTime.Now,
DateTime.Now.AddMinutes(FormsAuthentication.Timeout.TotalMinutes),
isPersistent,
JsonSerializerService.ToJson(identity),
FormsAuthentication.FormsCookiePath);
string encryptedTicket = FormsAuthentication.Encrypt(ticket);
var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
cookie.Path = FormsAuthentication.FormsCookiePath;
cookie.Expires = DateTime.Now.AddYears(1); // good for one year
I appreciate that I can change my above code to optionally set expires
if (isPersistent)
cookie.Expires = DateTime.Now.AddYears(1); // good for one year
An example application has been created @ GitHub. https://github.com/chrismoutray/AuthSample This basically shows that even by setting the isPersistent flag to true the cross browser authorization doesn't work.