Enabling sticky sessions on a load balancer

22,048

Solution 1

zeencat, take a look at http://msdn.microsoft.com/en-us/library/ms178586.aspx at the State Server Mode section:

StateServer mode stores session state in a process, referred to as the ASP.NET state service, that is separate from the ASP.NET worker process or IIS application pool. Using this mode ensures that session state is preserved if the Web application is restarted and also makes session state available to multiple Web servers in a Web farm. To use StateServer mode, you must first be sure the ASP.NET state service is running on the server used for the session store. The ASP.NET state service is installed as a service when ASP.NET and the .NET Framework are installed.

From what I understand the ASP.Net state service runs on one server, as a service called ASP.NET state service, both servers will have the same web.config file:

<configuration>
  <system.web>
    <sessionState mode="StateServer"
      stateConnectionString="tcpip=SampleStateServer:42424"
      cookieless="false"
      timeout="20"/>
  </system.web>
</configuration>

This way, the session is stored on the server who hosts the service.

Hope it helps, []

Solution 2

Also look at using ElastiCache if you are in AWS or Redis if on premise as your ASP.NET session store instead of using sticky sessions. It has more advantages in terms of auto-scaling, load balancing and I would say performance. More info at http://blogs.msdn.com/b/webdev/archive/2014/05/12/announcing-asp-net-session-state-provider-for-redis-preview-release.aspx

Share:
22,048
zeencat
Author by

zeencat

Database &amp; .Net Senior Developer Developing SSIS custom components in C# for SQL Server 2005, 2008 and 2012.

Updated on January 20, 2020

Comments

  • zeencat
    zeencat over 4 years

    Any advise on this one would be greatly appreciated, I've been researching all morning and I'm still scratching my head. I started at a new company a few weeks ago, where I'm the only .NET developer as the development was originally done by an outsourcing company and I've been asked to research. My knowledge of the existing system is extremely limited but from what I can gather the situation is as follows.

    We would like to enable sticky sessions on an asp.net web site. From my research I have gathered, I need to do the following steps. We are using the ASP.NET State Service

    The setup is a load balance server which services two web servers.

    1. Ensure that both web servers have the same machine key.
    2. Ensure that the websites have been precompiled before deployment. For serialisation of objects by ASP.NET State Service.
    3. Ensure that the application path on the iis metabase is identical on both web servers.

    I bit of knowledge I'm lacking is where are the sessions are stored. Are the sessions stored on the load balancer, can they be stored on the load balancer? From what I've read they are stored by the ASP.NET State Service, should the service be running on the load balancer therefore the sessions are stored o the load balancer.

    From what I understand the ASP.NET state service runs on each of the web servers and they just talk to each other so that the sessions are stored across both servers. I assume that the way they do this is based on the type of algorithm that is used. Any information would be greatly appreciated.

  • Sachin Trivedi
    Sachin Trivedi about 8 years
    What is the "SampleStateServer". is it my machine name ?
  • drigomed
    drigomed about 8 years
    @SachinTrivedi, I believe it's the name or IP of the server used to store the session. Not sure :)