Using Session Variables? Might Want To Think Twice

  Well I am working on website that uses asp.net and IIS 7.5.  Not uncommon I imagine.  Well, after successfully getting the project to work on my local environment I moved to it to the dev site.  Tested it working fine on IE10, IE11, Firefox, Safari, Chrome on dev.  Then I moved it to live, then the troubles started.

  I started fiddling with the modules I almost immediately noticed oddities occurring.  After more testing I had a nice list of problems.  As is my preference, I always try to test things as much as possible before we have to release.  Our shop is not strict with that you see, we have a guy that likes developing and testing on live ahah (it's horrible but senior to me by 10 years or so).
  
  1. The checkboxes would sometimes not have a check even after the postback of the page.  Sometimes checking a checkbox would clear all the checkboxes.
  2. After checking a row a separate listview has a list of items checked, but sometimes (noticing an obnoxious trend?) a checkbox would be checked, but no items would be in the selected listview.
3.  After an ajax callback sometimes all checkboxes and the listview with the selected items would be blank.

  There were a couple of other problems when I moved to live, but I will save those for a different post.  However, this was clearly a difficult problem.  Erratic run-time errors that only occur in a certain enviroment.  One of the guys at the office who I was complaining (talking) to was telling me that he had encountered something similar and to take a closer look at the server settings.

  Well he was right on.  Once I copied the settings that differed over to the development server from production the same problems started occurring.  Basically we had the application pool on 30 minute recycling schedule.  When the application pool is recycled lots of things are lost, like session variables (link).   However, that is not the end of the matter, because I was certainly experiencing that odd behavior within minutes, not in 30 minutes periods.  We also had a max memory limit (forgot what the setting was),  and I believe was another part of the problem.

  I made logging of various events and it was the case that session variables would be Nothing (aka Null) sometimes.

So to resolve this issue I stored that information in a hidden field control, and all the others in Viewstate.  Still need to take a second look at the whole things since encryption may be necessary.  Not sure if our Viewstate is encrypted or not.  And since some values appear in javascript there may be even more of a need to review it again for security purposes.

 But still, it's important to realize that sometimes Session variables may not work as expected in your environment.

Comments

Popular posts from this blog

Asp.net Publishing Broke Site - "App_WebReferences is not allowed because the application is precompiled"

Telerik - Custom Group Footers In RadGrid

Bootstrap Modal Popup is Grayed Out