O'Reilly logo

ASP.NET 2.0 Cookbook, 2nd Edition by Geoffrey T. LeBlond, Michael A Kittel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

12.4. Maintaining Session State Across Multiple Web Servers

Problem

You need to configure your application to maintain session state across multiple web servers—for example, in a load-balanced web farm or web garden.

Solution

When the data stored in session is easy to re-create or is not critical, configure your application to use the ASP.NET State Service using the following four steps:

  1. Set up a new server with the .NET Framework installed to maintain session state on behalf of your application.

  2. Start the ASP.NET State Service on the designated machine.

  3. Modify the application web.config file on its current web server, as shown next, setting the <sessionState> element’s mode attribute to StateServer and StateConnectionString attribute to the IP address and port of the state server:

    	<sessionState
    		mode="StateServer"
    		stateConnectionString="tcpip=10.0.1.11:42424"
    		cookieless="false"
    		timeout="20" />
  4. Copy the contents of the root folder and subfolders of your application on the current web server to the additional web servers.

When you must not lose any session information if server problems arise, use SQL Server to store all session information, as follows:

  1. In the instance of SQL Server that you will use for this purpose, install the special tables and stored procedures that ASP.NET requires by running the InstallSqlState.sql script provided with the .NET Framework located in the %SystemRoot%\Microsoft.NET\Framework\%VersionNumber%\ folder.

  2. Set up a database user with read/write access to the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required