I know when application pool is recycled a new worker process is initiated but I am confused with how expired and valid sessions are treated in this process? which passes to new worker process thread to and which are eliminated? what it will do with:
after recycling, when User A and User B will request then what will be their session statet?
If you have a single web server, and you've used the default InProc
mode for SessionState persistence, then any data that you've added to the session's Dictionary in your server code will be lost during an App Pool recycle - after the recycle, when your code next accesses an entry in the SessionState
dictionary, it will return null
.
This will similarly happen if you have multiple web servers across a load balancer, with session state incorrectly configured as InProc
, and the user returns to a different server (i.e. without sticky routing).
(The Session State cookie stored on the browser may still be valid for several minutes yet).
The way to allow Session State to 'survive' an App Pool recycle, server crash, or to span across a farm of servers is to persist data stored in SessionState
, so that the server (or servers) can again retrieve the data when the user's session returns. Easiest is to use one of the out of the box solutions, viz a separate StateServer
process, or store state in a SqlServer
database. Custom persistence is also an option.
One caveat - note that any data that you store in an 'out of process' mode such as StateServer
or SqlServer
needs to be serializable - this can be a breaking change when you switch out of InProc
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With