Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 917
marcusstarnes Avatar asked Nov 23 '25 04:11

marcusstarnes


1 Answers

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];
like image 162
gbs Avatar answered Nov 24 '25 19:11

gbs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!