After various conversations on both internal and external projects, I’ve noticed that some of our web projects were being developed using a Session state called InProc.
InProc means In-Process, so IIS is hosting all of the
Session[“Dom”] = “Idiot!”;
variables. Now, if the web application eats up too much memory, IIS 6 and above can be configured to recycle the Application pool – a contained unit of web sites, in order to free up memory. This is good for IIS but baaaad news for your website, as everything in the Session is lost – that could be shopping basket, current order status, user details! InProc is a bit of a quick and nasty method of developing as it just does its job, assuming that you are not going to host this to a larger audience (over about 5 users).
As I found out with any large project, nothing goes to plan, so, the best thing to do is to use StateServer and not InProc – but WHY?
StateServer is a totally out-of-process service that runs on either the same web server or a different server entirely. Session data is saved to this service so if the AppPool recycles, you have no problems whatsoever. Also, the data needs to serialize properly in order for it to be saved to the service.
Whats the point I hear you ask? Well, the point is that if you use InProc and your application gets load balanced (often without your knowledge), the website won’t work properly. Remember, load balancing is decided, by either the hardware or the software, to help manage the network traffic to a destination server. So 1 request to go to Server1 and another or Server2, or even ServerX! Youch! So your site’s Session could be stored on another machine.
StateServer works because all of the web.config’s point to the same machine, so they all work off that one service.
The other option is SQLServer, which stores it in SQL Server, which is more for web farms (multiple physical PCs), rather than web gardens (multiple virtualized PCs). Or you can use Custom for a custom implementation (e.g ODBC or XML), or Off to turn it off completely.
Therefore, a good recommendation is to always change your web.config to say:
<sessionState mode=”StateServer” … />
And start the ASP.NET State Service on your machine. This way to can always revert to InProc if you need to, but you are still ready for the switch over.
Believe me, it’s a lot easier to start out this way, rather than have to work backwards.
It is always a worthwhile exercise!