ASP.NET SQL Session State in a Web Farm

I found out the hard way that storing session in a SQL server takes a little more work then most of the books that I have read talk about.  Most articles don?t talk about what settings you should have when you are in a web farm.  This article will hopefully point you in the right directions and keep you from the headaches that I had.

One of the first things to check is the easiest to fix.  You will need to make sure you have a constant machine key between servers.  The machine key is used for encryption and decryption of cookie data.  Unless you set the machine key to a specific code on each machine they will use their own unique key, so when your connection switches from one server to the other server it can?t decrypt the data and you lose your session.

Microsoft has a couple articles on their site on how to create the machine keys and where to place them.  You can place this machine key in your machine.config or web.config files.

  • 312906 HOW TO: Create Keys by Using Visual C# .NET for Use in Forms Authentication
  • 313091 HOW TO: Create Keys by Using Visual Basic .NET for Use in Forms Authentication

The other fix is a little more complicated to change and is less likely to be a problem for everyone.  This problem happens when you add more web sites to one server then to the other server then you try to load balance two web sites.  What happens is that the application path for the web sites is different on each server.  For example on one server you have a web with an application path of \LMW3SVC2 and on the other server it has an application path of \LMW3SVC4.  The problem is IIS uses the application path to store the data, and if they don?t match you will lose your session.  You will have to synchronize the application path for the web sites on all your web servers in the web farm.

Microsoft has an article on this problem and how to fix it.  If you think this is your problem please check out this article.

  • 325056 PRB: Session State Is Lost in Web Farm If You Use SqlServer or StateServer Session Mode

When I was going through this we had both of these problems, and after running though these steps we are now using SQL session state on our web site, on a three server web farm.

12 thoughts on “ASP.NET SQL Session State in a Web Farm”

  1. Great website and setup for weather. I’ve done weather for about 3 yrs, weather spotter for the county and EMA Hazmat Team.

    Virtual weather, had that on the Lacrosse systems, I was using but, i went thru two units, upgraded to the Davis Advantage Pro2. Have any problems linking the software with the Davis.

    Weatherlink isn’t the best, I liked virtual weather. Having big problems getting my data to download thru CWOP.

    I’m a newbie on the block, KD8GIZ, been listening for years, but never took the venture to get the license.

    Dealing with the county EMA, Hazmat and military fubctions, getting my license seemed essential in todays present world. Ham operator’s will place a major function, when things go wrong by mother nature or present world terrorism.

    Great setup

    CW0578/KD8GIZ
    general@wcoil.com
    raptor@woh.rr.com

  2. Great website and setup for weather. I’ve done weather for about 3 yrs, weather spotter for the county and EMA Hazmat Team.

    Virtual weather, had that on the Lacrosse systems, I was using but, i went thru two units, upgraded to the Davis Advantage Pro2. Have any problems linking the software with the Davis.

    Weatherlink isn’t the best, I liked virtual weather. Having big problems getting my data to download thru CWOP.

    I’m a newbie on the block, KD8GIZ, been listening for years, but never took the venture to get the license.

    Dealing with the county EMA, Hazmat and military fubctions, getting my license seemed essential in todays present world. Ham operator’s will place a major function, when things go wrong by mother nature or present world terrorism.

    Great setup

    CW0578/KD8GIZ
    general@wcoil.com
    raptor@woh.rr.com

  3. Pingback: yah-underground
  4. Pingback: yah-underground
  5. Pingback: yahoo booters
  6. Pingback: yahoo booters
  7. Pingback: juegosjuegos
  8. Pingback: juegosjuegos
  9. Pingback: agame
  10. Pingback: agame
  11. Pingback: mangafox
  12. Pingback: mangafox

Leave a Reply

Your email address will not be published. Required fields are marked *