9.4. Maintaining Session State Across Multiple Web Servers
Problem
You need to configure your application to maintain session state across multiple web servers.
Solution
When the data stored in session is easy to recreate or is not critical, configure your application to use the ASP.NET State Service using the following steps:
Set up a new server with the .NET Framework installed to maintain session state on behalf of your application.
Start the ASP.NET State Service on the designated machine.
Modify the
modeattribute of the<sessionState>element of the applicationweb.configfile on its current web server to specify the ASP.NET State Service.Copy the contents of the root folder and subfolders of your application on the current web server to the additional web servers.
When it is critical to not lose any session information if server problems arise, use SQL Server to store all session information, as follows:
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.sqlscript provided with the .NET Framework.Set up a database user with read/write access to the
tempDBdatabase.Modify the
web.configfile, as shown next, setting the IP address to the address of your SQL Server machine and replacinguserandpwdwith the settings for the database user with read/write access to thetempDBdatabase.<sessionStatemode="SQLServer"sqlConnectionString="data source=10.0.1.12;user id= ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access