marcusstarnes
marcusstarnes

Reputation: 6531

Retrieve Forms Authentication Expiration Date/Time

I'm using forms authentication and currently create a forms auth ticket when a user logs in, and set an expiry of about 5 days if they have requested to persist the login.

I now need to create an additional cookie to store some additional settings and IF a user is authenticated, I would like to be able to get the date/time that their forms auth ticket is due to expire, whether the forms ticket is persistent, and set that as the expiry for my other cookie, but I don't know how to get that forms auth expiration date/time or check if it's persistent.

Can this information be extracted from the encrypted forms auth ticket?

Upvotes: 3

Views: 2783

Answers (1)

gbs
gbs

Reputation: 7276

Use the FormsAuthenticationTicket.

FormsIdentity identity = HttpContext.Current.User.Identity as FormsIdentity;
FormsAuthenticationTicket ticket = identity.Ticket;
//ticket.Expiration
//ticket.IsPersistent

Plus you can get the cookie like:

HttpCookie cookie = Request.Cookies[FormsAuthentication.FormsCookieName];

Upvotes: 9

Related Questions