"Randomly" Losing Session State on IIS 6

In IIS 6/Windows 2003, you may notice that session or cached information sometimes “disappears”, seemingly at random. No, it’s not gremlins…it could very well be your Application Pool settings.

If you are running in IIS6 mode, your web sites will be using Application Pools. If your app pools are set to run using multiple processes, then cache & session information will be inconsistently accessible to aspx pages. Check the # of processes for your IIS 6 app pool. If it’s 1, then that’s the cause. Or if different vdirs on your site have different pools, that would also cause the results you’re seeing.

Why? Imagine your app pool has two processes, A & B. An ASPX page stores an item in the cache or session. Through random luck, it gets stored in process A. Now the user requests another page & asks for that item from cache or session. But this time, the ASPX page might look in process B. Since the item is stored in process A, not process B, it will come up emptyhanded. If your ASPX page then re-stores the item during this call, it’ll store it in process B. And now you have two (possibly different) versions of the item, one in process A, one in process B. And who knows which one will get pulled up on the next ASPX request.

So, if you plan to use in-process session state or cached items, be aware of the above, or else set the number of processes of your Application Pools to 1 (uno).

It’s worthwhile to be cautious if you assume the cache will stay “in sync” with a database. Memory conditions, app restarts, etc. can expire items in the cache quite easily.

0