Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how session timeout works? 2

Status
Not open for further replies.

Sniipe

Programmer
Oct 9, 2006
115
IE
I have this code:
Code:
private void checkSessionExpired()
{
   if (Context.Session != null)
   {
      if (Session.IsNewSession)
      {
         string szCookieHeader = Request.Headers["Cookie"];
         if ((null != szCookieHeader) && (szCookieHeader.IndexOf("ASP.NET_SessionId") >= 0))
         {
            Response.Redirect("gblSessionExpired.aspx");
         }  
      } 
   }
}
Its in the baseForm, which every page inherits. The problem is that Session.IsNewSession is always false for me.

I was thinking, an easier way perhaps (I'm new to sessions), is to set a session timeout once at the start. And then check if a session that I set at the start IsNull... would that work? If the session variable is null then redirect to a "session has timed out page". Any ideas?
 
I think I'm on the right track now. I've been told not to have the base page in a webForm, and am now putting it into a .cs page.
What happens is that the base form gets called after the page that it inherits. - This is due to the fact of the HTML associated with webForms.
Hopefully it will be working soon.
 
But still, it's within the current request. Session.IsNewSession should return true when session has started during the current request.

Try stepping through Session_OnStart to see why you're never getting true for Session.IsNewSession.
 
Is your web server set up to expire sessions? I mean, if you are always logging on from the same address, you might always be reusing the session if it doesn't expire?

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Thanks stevexff and bangerman, I'm embarrassed to say that session_onStart happened earlier than I expected. I'm using dummy login pages and one of them had a session value.
 
I think we've all had experiences like that from time to time. Still, at least you 'fessed up to it...[smile]

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
ah, yeah. I always fess up, cause there is nothing worse than coming onto a forum and searching for a similar question and u don't see an answer :)
Granted they are not going to see an answer here either, but still its handy to have a thread thats complete rather than hanging in mid air.
Thanks again, appreciate the time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top