Wednesday, July 30, 2008

Error: Lost ASP Session State on IIS 6.0

What happen?

Recently, I migrated my project's web tools from Windows 2000 to Windows 2003.All is working fine until received an issue from customer saying that they are not able to submit requests through the web tool. They keep redirected back to the main page for no reason.
After doing troubleshooting with customer, I suspected that it has to do with Session as in the web tool, it's using Session to keep track of user's access information. This will only happen if the session has ended/timeout and causing the logic to redirect to main page for re-login.

What's the problem?

Why is the Session keep timeout so fast? Why do we lost the Session so fast even though by default it was suppose to time out in 20 minutes.

The solution?

I googled my problem and found the solution in this blog. http://blogs.msdn.com/david.wang/archive/2005/09/19/Why_do_I_lose_ASP_Session_State_on_IIS6.aspx
Thanks to this blog that it helps to solve my problem.

Basically, the possible causes:

  1. This situation happens if w3wp.exe are recycled. The in-process session state will be lost. As Windows 2003 is using IIS6.0, the ASP session state is stored in-process with whatever w3wp.exe that is executing ASP.DLL to process your ASP application. This state is valid for as long as the w3wp.exe is running.
  2. Enabling Web Gardens, where maximum number of worker process > 1. Web Garden introduces multiple processes to service requests while in-process state is not automatically copied across processes. If you have code that relies on sessions, and you enable the web garden feature (set max processes to > 1 for an app pool), you will experience this "curious" "intermittent" loss of sessions (or "unexplainable logouts"). The problem isn't work process recycling, nor even application domain restarts (other problems that can kill sessions or force logouts). Instead, it's just that the web garden feature can cause your requests to eventually be directed to a new worker process where the session you had is not existing.

Try:

  1. Disable periodic recycling.
  2. Try not enable web gardens (if not needed)