Way back in ASP.NET version 1.1, I wrote one of my first asp.net web sites for a client that depended pretty heavily on session variables. Without getting into the arguments about the wisdom of using session variables in the first place. Let’s just say that we needed to store state information and that session variables were the best way to handle the issue.
We spent months working on the web site. Everything worked fine during development and even as we tested the application… on our local computers.
But, once we put the application up on the server. A shared server where a lot of other asp.net applications were also living, we suddenly found that the application would work, mostly. But, every once in a while the application would act like it couldn’t find the session variables we were trying to store.
Now, we all know that programs do pretty much what they are told. So, the question you start asking yourself in a situation like this, where it works most of the time, is why would this not work only some of the time? Why would the session variable get lost?
Well, the little known fact, at the time, is that the ASP.NET worker process recycles itself to take care of all the things that could go wrong. Excessive memory usage, runaway processes, etc… And, when the worker process recycles, all of the in-proc session variables go away.
This wouldn’t be a problem, except in-proc is the default in ASP.NET. It still is.
However, Microsoft provided two remedies. The Session Server and the SQL Session Server. If you implement either of these, than you could even turn off your computer and turn it back on and the sessions would still be there.
Many people still believe that these two servers are only for web farms. But, unless you are running on your own server, you should be using one of these two servers instead of the default, in-proc, server. In fact, I would suggest that even if you are running your own server you should also use a session server of some time. You never know for sure when the worker process will recycle and kill all of your session variables.
There are a couple situations that will not work with session servers. One is that you will no longer be able to store COM objects into the session variable. The other is that you will not be able to store any objects that can not be serialized. But, you shouldn’t be storing COM objects in the session variable anyhow and you can make just about any object serializable in one way or another.
Finally, because non-serializable object can be stored in an in-proc session store, but can’t be stored into a session server, you should turn on the session server on your development machine and store you session variables into it instead of using the in-proc session server during development.
Other post in ASP.NET
- ASP.NET GridView Edit All Rows At Once - October 30th, 2007
- Validating A WebForms Checkbox . . . - January 4th, 2008
- ListView and the DataPager - January 7th, 2008
- The case of the disappearing session variables - January 14th, 2008
- Storing a DataRow into a Session (server) variable - January 15th, 2008
- The point of a multi layer architecture - January 31st, 2008
- FormView Edit and Add - May 12th, 2008
- Virtual Files using HttpContext.RewritePath() - July 17th, 2008
- ASP.NET AJAX using JSON - Here's how. - August 4th, 2008
- SystemException: The trust relationship between the primary domain and the trusted domain failed - November 18th, 2008
- GridViews - Multiple Rows Per Record - December 17th, 2008
- Response.Redirect() executes too soon on the Server. - January 27th, 2009
- Tab Control ActiveTabIndex Lost on Postback - February 25th, 2009
- ASP.NET Application_Error Detecting 404's - March 2nd, 2009
- Infinite 302 Loop - How would you even know? - March 11th, 2009
- Unable to find connection...for object web.config - March 18th, 2009
- Dynamically Change class Attribute From ASP.NET - September 29th, 2009
- HttpContext.Items vs Session - October 12th, 2009
- Access a control by ID From Within a Databound Control - November 2nd, 2009
- GridView and Updating A Row Manually - November 4th, 2009
- Embedding Google Search Appliance Results in ASP.NET - November 5th, 2009
- ASP.NET Cross Domain Form Submission - November 11th, 2009
- ASP.NET Interview Questions For New College Graduates - November 12th, 2009
- ASP.NET Dynamic Validator - November 16th, 2009
- The Google Appliance and Forms Authentication - August 4th, 2010
- Prevent Postback on Buttons - October 11th, 2010
- Azure CDN Blob Storage Case Sensitive Issue - April 17th, 2012
- ASP.NET JSON and ViewState - September 25th, 2012
- Panel DefaultButton does not work - December 25th, 2012
- Why CSS ID selectors are Evil in ASP.NET Web Forms - February 26th, 2013
- Sorting the ListView in ASP.NET - March 5th, 2013
- Multi-Step Processing in ASP.NET - May 8th, 2013
- ASP.NET Web Design Software - May 15th, 2013
- Test Sending Email without a Server in ASP.NET - June 5th, 2013
- Tracking Down Performance Issues in ASP.NET - July 24th, 2013
- Unrecognized Tag Prefix or Device Filter ‘asp’ - July 31st, 2013
- WebServices – Error Handling - December 11th, 2013
- Converting a DataList to a ListView - December 25th, 2013