Connecting Tech Pros Worldwide Forums | Help | Site Map

ASP Session Early Timeout

Newbie
 
Join Date: Aug 2008
Posts: 4
#1: Aug 10 '08
I've written a single load AJAX application that uses Session variables to store User information etc.

Upon validating the username and password entered against the values stored in a database I wither the current session ID to a a variable as:

Expand|Select|Wrap|Line Numbers
  1. Session("VSession")
  2.  
  3. On each HTTP Request, I check the session for expiration.
  4.  
  5. Function ValidateSession()      '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  6. If Session("Vsession") = Nothing then 'Session expired 
  7.     Session("State")="Expired"
  8. Else
  9.     Session("State")="Active"
  10. end if    
  11.  
  12. End Function'------------------------------------------------------                
I'm using the default Session.Timeout = 20 in the Global.asa file.

But sometimes it is just a matter of seconds and Session("VSession") is Nothing. Rarely will my session variables survive 10 minutes. Any idea would be greatly appreciated. - GrnMtn
Newbie
 
Join Date: Aug 2008
Posts: 4
#2: Aug 11 '08

re: ASP Session Early Timeout


Afte posting my question I realized I probably didn't explain my issue very well so here's an overview of what's happening:

1) A user loads the home page, (default,asp).
2) Upon entering the username and password, the information is authencated against the userdata in a database.
3) If the username / password are correct, then a session variable is set:
Session("VSession") = Session.SessionID
4) At this point all subsequent server client interaction is via HTTPRequest.

Expand|Select|Wrap|Line Numbers
  1. function LoadPage(RStr)
  2. {   var XMLreq = new ActiveXObject("Microsoft.XMLHTTP"); 
  3.     MLreq.open("GET", RStr, true);  
  4.     XMLreq.onreadystatechange = function()
  5.     if (XMLreq.readyState == 4) 
  6.     {   if (XMLreq.responseText.indexOf("Session Expired")!=-1)  
  7.         {  location = "../default.asp"
  8.         }
  9.             document.getElementById("DivMain").innerHTML = XMLreq.responseText;
  10.  
  11.     }
  12.     XMLreq.send(null); 
  13. }
  14.  
  15. when each HTTPRequest is received by the server I validate the session with the following function.
  16.  
  17. Function ValidateSession()     
  18. If Session("Vsession") = Nothing then 
  19.    Response.Write("Session Expired")
  20.    Response.End
  21. End if    
Hopefully this is a better explaination of what I'm trying to do. The problem is that while the Session.Timeout = 20 my sessions seem to expire at random times well short of 20 minutes. Any help would be greatly appreciated. -Dennis
jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,690
#3: Aug 12 '08

re: ASP Session Early Timeout


What program did you use to write your code (what is your ide)? I have heard of a bug, but it is apparently ide-dependent.

Jared
Newbie
 
Join Date: Aug 2008
Posts: 4
#4: Aug 12 '08

re: ASP Session Early Timeout


I'm doing this in Visual Web Developer 2005. - Dennis
Newbie
 
Join Date: Aug 2008
Posts: 4
#5: Aug 12 '08

re: ASP Session Early Timeout


I think I found the answer buried deep in the following blog:

http://blogs.msdn.com/david.wang/archive/2005/09/19/Why_do_I_lose_ASP_Session_State_on_IIS6.aspx

# re: Why do I lose ASP Session State on IIS6
Thursday, April 24, 2008 12:16 PM by John Homer
The ASP (not .Net) session timeout is stored in the ASP application configuration. This is accessed via the website properties (not the application pool) on the Home Directory tab. Click the configuration button and then select the Options tab. You may then set the ASP session timeout valus in minutes which is 20 by default. This will terminate any session afetr 20 minutes on inactivity.

Note that this is independent of the application pool settings. In fact, you don't even need an application pool to utilize this setting. For instance, you can configure IIS 6 to run in IIS 5 compatibility mode (or just use IIS 5) and then configure your ASP Application Protection (Home Directory tab in website properties) to "Low (IIS Process)" which will run the application in-process (inside the inetinfo.exe process instead of w3wp.exe or dllhost.exe). Even in this scenario, the ASP timeout setting mentioned above is still effective.

For ASP.Net you can configure the session timout in your application's web.config. Look for the following line and configure accordingly:

<sessionState mode="InProc" cookieless="false" timeout="20"/>

I'm still testing but after setting the Isolation Mode to IIS 5.0 I haven't had a unexpected session expiration in over an hour. - Dennis
jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,690
#6: Aug 13 '08

re: ASP Session Early Timeout


Good Info! thanks for sharing your solution.

Jared
Reply