views:

758

answers:

3

We've got an ASP.Net 2.0 (VS2005) application that works fine locally, but sometimes loses session state when deployed on the remote server.

I suspect a possible issue with IIS recyling the application and thereby blowing away the users' session state. However, the server is remote not under our control... so we can't simply fire up IIS Admin and check out the application settings. Another possible cause, of course, would be clients rejecting the ASP.Net session cookie for some reason.

(We've pretty much ruled out an error in our code because it's a simple app and it never attempts to remove anything from the Session object but of course... those are famous last words, eh?)

How would you diagnose this programatically?

I'm mostly trying to figure out how to diagnose the issue; if overzealous application recycling is the culprit it shouldn't be too hard to code around.

I'm sure this is a common issue for ASP.Net developers.

+1  A: 

Add some logging code to the global.asax Application_Start method and you'll be able to see when/if your loss is caused by application restarts(or at least, you'll see when the server is starting, if you know a session was lost at the same time, you know your culprit).

A workaround would be to use out of proc session state (probably would have to be SQL based if you don't have control of the server). It takes a little extra work to your code because everything you store in Session has to be serializable, but solves the problem of app restarts causing session loss.

Chris Shaffer
+2  A: 

Here are a couple of links that may help in troubleshooting this if you can change some settings:

Logging Worker Process Recycling Events in IIS 6.0 (IIS 6.0)

Logging ASP.NET Application Shutdown Events

JB King
A: 

IIS configured for more than One Worker Thread (Web Garden) in the Application Pool can cause loss of session state.

Gordon Bell