Configure a State Server to Maintain Session State (IIS 7)
Applies To: Windows 7, Windows Server 2008, Windows Server 2008 R2, Windows Vista
Out-of-process session state mode preserves session state data by running in a worker process outside the worker processes where ASP.NET applications are running. One type of out-of-process session state uses a state server, which depends on the Windows state service, Aspnet_state.exe. The advantage of this configuration is that session state is preserved when the application's worker process recycles. Using a state server is recommended for medium-sized applications.
When a state server runs on the same Web server that contains the applications for which it maintains state, a Web garden configuration is supported. One disadvantage of this approach is that if either the Windows state service or the Web server itself goes down, all session state information is lost. For increased protection of session state data, consider using a Web farm configuration with a separate server that stores session state and shares it among all servers in the farm. Another approach is to use SQL server to maintain out-of-process session state. For more information about how to use SQL server to maintain out-of-process session state, see Configure a SQL Server to Maintain Session State (IIS 7).
Important
The Windows state service (Aspnet_state.exe) must be running for in-process session state to take effect. By default, this service is installed when Windows ServerĀ® 2008 is installed and is configured for manual start. You must change the start behavior to Automatic.
Prerequisites
For information about the levels at which you can perform this procedure, and the modules, handlers, and permissions that are required to perform this procedure, see Session State Feature Requirements (IIS 7).
Exceptions to feature requirements
- None
To configure a state server to maintain session state
You can perform this procedure by using the user interface (UI), by running Appcmd.exe commands in a command-line window, by editing configuration files directly, or by writing WMI scripts.
User Interface
To Use the UI
Open IIS Manager and navigate to the level you want to manage. For information about opening IIS Manager, see Open IIS Manager (IIS 7). For information about navigating to locations in the UI, see Navigation in IIS Manager (IIS 7).
In Features View, double-click Session State.
On the Session State page, in the Session State Mode Settings area, click State Server.
Type a connection string in the Connection string text box, or click Create to create a connection string.
Type a time-out value in the Time-out (in seconds) text box. The default time-out value is 10 seconds.
(Optional) Configure cookie settings in the Cookie Settings area on the Session State page.
(Optional) Select the Use hosting identity for impersonation check box to use Windows authentication and the host process identity (either ASP.NET or a Windows service identity) for connections to the database.
Click Apply in the Actions pane.
Command-line
To configure a state server to maintain session state, use the following syntax:
**appcmd set config /commit:WEBROOT /section:sessionState /mode:StateServer /stateConnectionString:**string /stateNetworkTimeout: timeSpan /useHostingIdentity:True|False
The variable mode:StateServer sets the session state mode to store session data in a state server. By default, the variable string defines the connection string that the state server uses. The default setting is tcpip=loopback:42424. The variable timeSpan sets the time, in seconds, that the connection to the state server is maintained. The default is 10 seconds. The variable useHostingIdentity:True|False enables or disables the use of Windows authentication and the host process identity (either ASP.NET or a Windows service identity) for connections to the database. The default value is True.
Note
When you use Appcmd.exe to configure the <sessionState> element at the global level in IIS 7, you must specify /commit:WEBROOT in the command so that configuration changes are made to the root Web.config file instead of ApplicationHost.config.
For more information about Appcmd.exe, see Appcmd.exe (IIS 7).
Configuration
The procedure in this topic affects the following configuration elements:
<sessionState>
<sessionPageState>
For more information about IIS 7 configuration, see IIS 7.0: IIS Settings Schema on MSDN.
WMI
Use the following WMI classes, methods, or properties to perform this procedure:
- SessionStateSection.Mode property "StateServer" flag
For more information about WMI and IIS, see Windows Management Instrumentation (WMI) in IIS 7. For more information about the classes, methods, or properties associated with this procedure, see the IIS WMI Provider Reference on the MSDN site.
See Also
Concepts
Configuring Out-of-Process Session State Configuring Session State in IIS 7