Configuring ASP.NET Session State

In this example we will setup the different modes of session state management that ASP.NET supports.

SQLServer (out of process)
This is where the session state is store out of process within a database
StateServer (out of process)
This is where the session state is store out of process on a remove server
InProc (In Process)
This is where the session state is store in process on the local server

The fastest method is InProc, but if the worker process is recycled all information is lost.

You configure a web applications state management within the web.config using the sessionState element, below are a few important attributes

mode
InProc / SQLServer / StateServer / Off
cookieless
AutoDetect / UseCookies / UseDeviceProfile / UseUri
sqlConnectionString
The connection string to the SQL Server
stateConnectionString
The connection string to the State Server
timeout
The time in minutes a session can be idle for it is abandoned. Default 20 minutes.

To setup SQL Session State management you first need to create the database,

A installation script can be found in this folder

C:\Windows\Microsoft.NET\Framework\v2.0.50727\InstallSqlState.sql

But you should install it using

aspnet_regsql.exe

Make sure the database owner is sa


use ASPState
exec sp_changedbowner 'sa','true'

Then configure your web.config like this





To setup State Server Session Management, you need to start the ASP.NET State Service on the remote server using Administrative Tools > Services


C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_state.exe

Then configure your web.config like this





The standard approach is In Process Session State Management







Comments

No comments yet.

Add Yours

  • Author Avatar

    YOU


Comment Arrow




About Author

Robert

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning hands down.