The simplest way to detect if a session timeout occurred in an asp .net 2.0 web application use Global.asax Session_Start and Page_Load event.


Using Session["xxx"] value to determine the session timeout: This is a "quick and dirty" hack that can be introduced into an application to figure out whether a timeout has occured. We need to do two things here.
First, in Global.asax, create your own GUID and put it in the session object,


Session_Start(object sender, EventArgs e)
       // Code that runs when a new session is started
       Session["CustomSessionId"] = Guid.NewGuid();

, BasePage.cs which would have inherited Page, in PageLoad() event, check whether the Session["CustomSessionId"] == null, if it IS null, it means that the session was timed-out and AspNet runtime cleared it out.

    if( Session["CustomSessionId"] == null)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.