简体   繁体   中英

Programmatically diagnosing ASP.Net session loss due to application recycling?

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.

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

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.

I have found a scenario where session is lost - In a asp.net page, for a amount text box field has invalid characters, and followed by a session variable retrieval for other purpose.After posting the invalid number parsing through Convert.ToInt32 or double raises a first chance exception, but error does not show at that line, Instead of that, Session being null because of unhandled exception, shows error at session retrieval, thus deceiving the debugging...

HINT: Test your system to fail it- DESTRUCTIVE.. enter enough junk in unrelated scenarios, you would be able to reproduce this machine on your local code base too...:)

Hope it Helps, hydtechie

为应用程序池中的多个工作线程(Web花园)配置的IIS可能会导致会话状态丢失。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM