I was working on a website for one of my clients last day. When I was testing site, and I was getting an error “Object reference not set to an instance of an object”. I immediately got into the rescue. I started digging into the stack trace to find the clues about the error. After going thru it, I could find that the issue was caused when I tried to access a Session variable. ASP.NET was saying that the session variable was not set and thus threw the exception. But I was damn sure that I set the session variable before accessing it. OK. I exited the application and ran it again, and to my surprise it worked fine, but now, the same error started throwing at a different place in the code. If I refresh the page, it works fine. Each and every time I run the application, Session errors popped up at random places and in no pattern. This started driving me nuts. I was determined to find out the solution for this.
I goggled out for solutions and after much time, I could find out the problem was due to the IIS Settings in the Windows 2003 server.
What was happening is that, my website’s, application pool was configured as a web garden. This is done to improve the performance of a web site. What is does is that it allocates more number of worker process to handle the requests and hence it improves performance. But the downside of this is issues with Session.
By default, Session works in the InProc mode. Web gardens does not support session in InProc mode. So the solutions for this is either to set the number of worker processes in the IIS to1 or to change the Session Mode to use Sql Server.
To check weather your website uses a web garden
1) Open IIS
2) Open Properties of your website.
3) Check which Application pool is used by the website
4) Open Application pools in the right side pane of IIS
5) Right click and open properties of the Application Pool.
6) Change the no of worker process and its done!
