ASP.NET Session State Timeout Problem

Posted by user314827 on Stack Overflow See other posts from Stack Overflow or by user314827
Published on 2010-04-13T20:20:25Z Indexed on 2010/04/13 20:23 UTC
Read the original article Hit count: 566

I am trying to detect a session state timeout in my asp.net application and am unable to do so. I have a base class that derives from System.Web.UI.Page as follows:-

public class BasePageSessionExpire : Page
{
    override protected void OnInit(EventArgs e)
    {
        base.OnInit(e); 
        if (Context.Session != null)
        {                
            if (Session.IsNewSession)
            {                    
                string szCookieHeader = Request.Headers["Cookie"];
                if ((null != szCookieHeader) && (szCookieHeader.IndexOf("ASP.NET_SessionId") > 0))
                {
                    Session.Abandon();
                    Response.Redirect("~/SessionExpired.aspx",true);
                }
            }
        }
    }
}

All the pages I need session state checking on derive from this base class instead of "System.Web.UI.Page". Also, all these pages have EnableSessionState="True". I have a blank Session_Start() method in my global.asax file if that is relevant at all.

For some reason after the first request, the "Session.IsNewSession" property is always false. It is true only for the first request and then is always false. I have my timeout set to 1 minute. The session never seems to timeout. What am I missing here ?

Thanks in advance.

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about session