Skip to content

Instantly share code, notes, and snippets.

@eirikb
Created April 13, 2013 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eirikb/5377529 to your computer and use it in GitHub Desktop.
Save eirikb/5377529 to your computer and use it in GitHub Desktop.
protected void Application_PreRequestHandlerExecute()
{
if (!(Context.Handler is IRequiresSessionState)) return;
var authenticationCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
if (authenticationCookie == null) return;
var authenticationTicket = FormsAuthentication.Decrypt(authenticationCookie.Value);
if (authenticationTicket == null || authenticationTicket.Expired) return;
if (Membership.GetUser() != null) return;
FormsAuthentication.SignOut();
Response.Redirect(FormsAuthentication.LoginUrl, true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment