Web Development & Execution
Anonymous
by Anonymous
share this
?fl
« Back to the Blog

Storing aspnet session state in sql server

07/27/2010
Storing aspnet session state in sql server

In a single server configuration you might want to use a session state server in order to facilitate restarting Internet Information Services (IIS) without killing all active Web site sessions. In a server farm environment you should use an out-of-memory medium for storing asp.net session state in order to avoid use of sticky routing in the load balancer.

Here's the command you need to execute from the command line on the server where MS SQL Server is installed. The command installs the necessary tables and stored procedures which enable session state management.

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727> aspnet_regsql.exe -ssadd -sstype c -d [YOURDATABASENAME] -E

In your web application, all you need to do to switch from in-memory session management to SQL server session management is add the following node into the section of the web.config file:

<sessionState cookieless="AutoDetect"<blockquote>
      mode="SQLServer"
      sqlConnectionString="[YourConnectionStringGoesHere]"
      timeout="30"
      allowCustomSqlDatabase="true"
      compressionEnabled="true"
          /></blockquote>

Note: compressionEnabled="true" attribute is new to .NET Framework v4.x. According to the ASP.NET 4 and Visual Studio 2010 Web Development Overview whitepaper, the attribute enables shrinking of the serialized session state before writing it to the database. This improves application performance.

Thanks!

Thank you for contacting us!

We'll be in touch!

Back Home ×