views:

1192

answers:

5

I have an iframe keep alive (iframe that hits a page, defibrillator.aspx, on my site every few minutes to keep the session alive) on my masterpage for an asp.net app. This works most of the time but every so often my session variables return null during the page load on my defibrillator page. At first, I thought the session was being timed out by the server for some reason so I put some logging into the Session_End event in the global.asax but it was never hit.

Any ideas what could cause the session to be lost.

+2  A: 

Many things can cause session to be lost. An AppPool recycle, iisreset, the client could lose its session cookie, etc. Without knowing more it is difficult to tell what is the problem.

If session is so critical that you poll the application to keep the worker process from sleeping perhaps you ought to look into persisting your session state to SQL Server.

Andrew Hare
A: 

If the chosen persistence mechanism is InProc then it can be triggered by many things. Totally counter-recommended for a production environment.

Andrei Rinea
+1  A: 

I had this same sort of problem, storing a shopping cart state in Session but having it randomly return null instead. I think I found the answer on Bertrand Le Roy's blog, which seems to work for me:

Session loss problems can also result from a misconfigured application pool. For example, if the application pool your site is running is configured as a web farm or a web garden (by setting the maximum number of worker processes to more than one), and if you're not using the session service or SQL sessions, incoming requests will unpredictably go to one of the worker processes, and if it's not the one the session was created on, it's lost. The solutions to this problem is either not to use a web garden if you don't need the performance boost, or use one of the out of process session providers.

Blog

MattGWagner
A: 

I have strange problem for Session.

Whenever I am trying to login I am storing User Information in Session, now that works fine everytime except first time. So even if i am login and valid user i need to login twice, because some how my session value got null for first time, but for subsequent login value is persist and no problem. I tried debugging each and every scenario to find mistakes in code, but there is no mistakes. Session is getting null on redirection of page. Any idea or help?

Jordon