1

Possible Duplicate:
How to Check whether Session is Expired or not in asp.net

What is the best way for a page to detect if a session has timed out in the code behind? I found the below code in a blog (http://mattslay.com/detecting-session-timeout-in-asp-net/). Is is ok or is there a better way?

if (Context.Session != null && Context.Session.IsNewSession)
{
     string cookieHeader = Page.Request.Headers["Cookie"];
     if ((null != cookieHeader) && (cookieHeader.IndexOf("ASP.NET_SessionId") >= 0))
          return true; // timeout occured
     else
          return false;
}
Community
  • 1
  • 1
Ben Cameron
  • 4,335
  • 6
  • 51
  • 77

1 Answers1

2

I suggest you to treat this treatment in your Global.asax file

void Session_End(object sender, EventArgs e)
{
   //Here you execute your treatments about end session
}

Link : http://msdn.microsoft.com/en-us/library/system.web.sessionstate.sessionstatemodule.end.aspx

Aghilas Yakoub
  • 28,516
  • 5
  • 46
  • 51