Session State Is Lost in Web Farm If You Use SqlServer or StateServer Session Mode
Published Feb 15 2019 05:25 AM 4,272 Views

One of the most common issues that users face when hosting their application in a webfarm is “unexpected loss of session state”. We face these issues when we store the session information inproc, especially when we don’t set client affinity in the load balancer level.

This is one of the main reasons why users opt for an outproc session storage technique (like a SQL server or State Server). But, when you are configuring a state server across a web farm, maintaining the session state across multiple servers and applications is a matter of challenge for which you must take care of a little configuration piece while setting your sites.

Let me give you a brief idea on what we can do and why we are supposed to concentrate on such configuration settings while setting up our sites in a webfarm environment.

  • When we make a request, a worker process will be spawned which is always associated with a site ID.
  • The user is assigned with a unique session ID when the session begins. The user will then send that session ID to the server for every request.
  • When the session information is stored in the SQL Server or state server, to uniquely identify the session information for each user specific to each application, it is associated with a primary key.
  • That primary key is a combination of the session ID assigned to the user (that you might see in the request header) and the application ID.

For example, the value looks like: ’13clw2vlrjio0d45opi0qg4500000002’ where 2 is site id

You should ensure that your website is associated with the same site ID in all the web servers which are behind a load balancer to avoid unexpected session state losses.When we are configuring the application in multiple servers and when the site ID’s are different in different servers, this primary key will become different for different servers. That will produce a behavior similar to storing the session inproc.

Conclusion:
Maintaining same site ID for the same application across all the servers in the webfarm is important and will help in maintaining the session state when going with out-of-proc approach in a multi-server environment

Please leave your comments if you have any questions around this or need any clarification.

Author: Nikita Habib

2 Comments
Co-Authors
Version history
Last update:
‎Sep 06 2021 02:47 PM
Updated by: