I'm trying to establish some authentication timeout expiration checking, and I'm noticing something a little strange. When the authentication period is still valid, the following code will give me a cookie:
HttpCookie authCookie = context.Request.Cookies[".ASPXAUTH"]; // .ASPXAUTH name defined in web.config
But when the authentication period has expired, the cookie is no longer in the Cookies array, and my result is null. I'm trying to build a FormsAuthenticationTicket
object from the cookie, to be able to check the expired property. Like this:
FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);
// check if previously authenticated session is now dead
if (authTicket != null && authTicket.Expired)
{
// send a Response indicating that they've expired.
}
But if the cookie goes away once the authentication period has expired, I can't even get that far. So is there something I'm doing wrong, or is that cookie not supposed to be there? And if not, how am I supposed to build a ticket to even check the Expired property?
Thanks very much.