Session Variables Lose Value Before Timeout


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 13 of 13

Thread: Session Variables Lose Value Before Timeout

  1. #1
    grant Guest

    Session Variables Lose Value Before Timeout


    I've got some ASP pages where the session variable values get blown away BEFORE
    the session times out. I can't understand it. For example: if a user
    logs into my ASP app using his password which is stored in a session variable,
    it will be fully accessible for a few minutes and then all of a sudden.....Wham
    session variable with password value is gone. And the session timeout is
    far from expired. The session variable is not being touched in any way
    after it gets initialized with a value.

    Anyone no what could be causing this?

    Thanks.

  2. #2
    Join Date
    Jul 2004
    Posts
    8

    I have the same problem.

    I'm trying to resolve a related issue. I have set the session timeout in my web.config file:

    <sessionState
    mode="InProc"
    stateConnectionString="tcpip=127.0.0.1:42424"
    sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
    cookieless="false"
    timeout="480"
    />

    I set a Session variable within a user login page as follows:

    Session("UserName") = "John Doe"

    Within each page of the site I check to see if the Session("UserName") variable still has "John Doe" as a value. If it doesn't I redirect to the login.apsx page (Response.Redirect("login.aspx").

    My problem is that the session seems to timeout after about 20 min. and the user gets redirected back to the login page too soon.

    Anyone know why the session timeout setting is not holding?

  3. #3
    Join Date
    Mar 2004
    Location
    Jacksonville Florida USA
    Posts
    228

    Re: I have the same problem.

    Originally posted by jringwald
    I'm trying to resolve a related issue. I have set the session timeout in my web.config file:

    <sessionState
    mode="InProc"
    stateConnectionString="tcpip=127.0.0.1:42424"
    sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
    cookieless="false"
    timeout="480"
    />

    I set a Session variable within a user login page as follows:

    Session("UserName") = "John Doe"

    Within each page of the site I check to see if the Session("UserName") variable still has "John Doe" as a value. If it doesn't I redirect to the login.apsx page (Response.Redirect("login.aspx").

    My problem is that the session seems to timeout after about 20 min. and the user gets redirected back to the login page too soon.

    Anyone know why the session timeout setting is not holding?
    why are you spamming your question in every other session thread, we can see your thread right below this.... The question the thread starter is asking is not even an asp.net session question, its an asp classic session question, the two act differently.

  4. #4
    Join Date
    Jul 2004
    Posts
    8
    Good call - many apologies. I'm a little agressive some times

  5. #5
    Join Date
    Jul 2004
    Posts
    1

    Thumbs up Re: Session Variables Lose Value Before Timeout

    Originally posted by grant
    I've got some ASP pages where the session variable values get blown away BEFORE
    the session times out. I can't understand it. For example: if a user
    logs into my ASP app using his password which is stored in a session variable,
    it will be fully accessible for a few minutes and then all of a sudden.....Wham
    session variable with password value is gone. And the session timeout is
    far from expired. The session variable is not being touched in any way
    after it gets initialized with a value.

    Anyone no what could be causing this?

    Thanks.
    I am having the same problem, and I'm not sure where else to try and temporarily store the information I need to. Cache is not guaranteed to be there when you need it, I can't write to the database everytime (too many times) and the information is per-user, so I can't use application variables.

    Grant is right in saying the the developer-set session variables disappear, but the session itself does not actually expire and the user still remains logged in to the site.

  6. #6
    Join Date
    Mar 2004
    Location
    Jacksonville Florida USA
    Posts
    228
    you can always dump the session, I mean if the user clicks a logout button session.abandon() will dump it all, does that help any?

  7. #7
    Join Date
    Jul 2004
    Posts
    1
    Originally posted by PeoFeo
    you can always dump the session, I mean if the user clicks a logout button session.abandon() will dump it all, does that help any?

    reg. te session timeout after 20 min... pl. check out the iis settings

    ... select your application - properties - configuration - goto options tab - set the session timeout

    this could be the reason

    cheers
    jr kumar

  8. #8
    Join Date
    Mar 2004
    Location
    Jacksonville Florida USA
    Posts
    228
    Originally posted by kumarjr
    reg. te session timeout after 20 min... pl. check out the iis settings

    ... select your application - properties - configuration - goto options tab - set the session timeout

    this could be the reason

    cheers
    jr kumar
    You can set it in iis, or the web.config, wherever you want, it still tends to fail. The asp.net session state is buggy, I rarely see it last even 20 minutes. If you want something to work in a timely manner use a cookie, do not worrie about accessibility, its not like the session isn't cookie driven, because it is (unless set to be otherwise).

  9. #9
    Join Date
    Jul 2004
    Posts
    8
    Yes I've stoped using Session completely - it's terribly buggy.

  10. #10
    Join Date
    Jul 2004
    Posts
    2
    Make sure you have something to the effect of this in your global.asa file in your web application.

    <SCRIPT LANGUAGE=VBScript RUNAT=Server>
    SUB Session_OnStart
    Session.TimeOut = 90
    END SUB
    </SCRIPT>
    This sets the session lenght to 90 minutes. You can set it to whatever you want. You can also do this on a page per page basis by including <% session.Timeout = 90%> on the top of your pages.

    We have used the session object on all of our web apps with no or little problems. Just make sure your app and web server are configured properly.

    Other than that I cannot think of any reason why your variables would be dissapearing unless you are using a web farm.

    http://www.w3schools.com/asp/asp_sessions.asp

    http://www.juicystudio.com/tutorial/asp/session.asp

  11. #11
    Join Date
    Mar 2004
    Location
    Jacksonville Florida USA
    Posts
    228
    Originally posted by dragonfly

    Other than that I cannot think of any reason why your variables would be dissapearing unless you are using a web farm.
    or the fact that the asp session is just buggy. I have tried all of that in my past experiments, I rarely see the session get up to or beyond the default time of 20 minutes. I asked Sujay at web matrix hosting (hes a bit of a pal of mine), and he said he hasn't either.

  12. #12
    Join Date
    Mar 2008
    Posts
    1

    When Using IIS6 with low volume of users.

    I had the same problem. (On a new Win2k3 server running IIS 6 - never had this issue on a Win2K box) With very low volume of users, usually not more than 1 user hitting the app during the timeout period.

    After browsing through ISS mmc, I became suspicious of a setting in the App Pool the site with the problem was using.

    I confirmed my answer here:
    http://support.citrix.com/article/CTX103672

    Like I said -its a setting of the App Pool the site is using on, with a very low volume of users hitting the app.

    Go to the App Pool for the site, to the Performance Tab.

    Either uncheck the box for:
    Shutdown worker processes after being idle for (time in minutes)
    or set the value to >= your set session timeout.

  13. #13
    Join Date
    Feb 2012
    Posts
    1

    Smile Using IIS 7 in a test environment

    I had a similar problem.

    The Application pool was timing out after 1 minute. I changed it to 20 and it solved this problem.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center