How to use a separate Windows service for state management in ASP.NET

Software developer can set ASP.NET to use a separate Windows service for state management with option StateServer: When software developer is going to use this mode, the objects he store in the session state must be serializable. Otherwise ASP.NET will not be able to transmit the object to the state service.

 

<?xml version=”1.0” encoding=”utf-8” ?>
<configuration>
     <system.web>
     <!— other settings are omitted. —>
     <sessionState
        cookieless=”AutoDetect” cookieName=”ASP.NET_SessionID”
        regenerateExpiredSessionID=”false”
        timeout=”20”
        mode=”StateServer”
        stateConnectionString=”tcpip=127.0.0.1:42424”
        stateNetworkTimeout=”10”
        sqlConnectionString=”data source=127.0.0.1;Integrated Security=SSPI”
        sqlCommandTimeout=”30” allowCustomSqlDatabase=”false”
        customProvider=””
     />
     </system.web>
</configuration>

 

This service will work on the same web server, but outside the main ASP.NET process, which gives a basic level of protection if the ASP.NET process has to be restarted. When state information is transferred between two processes time delay will be increased.

When this option is used, the software developer should specify a value for the stateConnectionString setting. This string identifies the TCP/IP address of the computer that is running the StateServer service and its port number. This allows software developer to host the StateServer on another computer. If he doesn’t change this setting, the local server, set as address 127.0.0.1, will be used. There is an optional attribute stateNetworkTimeout that specifies the maximum number of seconds to wait for the service to respond before canceling the request. The default value is 10 seconds.

Before application can use the service, the administrator has to start it. He can follow the next steps:
1. Select Start>Programs>Administrative Tools>Computer Management
2. Select Services and Application>Service node
3. Find the service called ASP.NET State Service in the list.
4. Now he can start and stop the service by right-clicking it.
5. He can modify its Startup Type setting to Automatic right-clicking it and select Properties. In this case Windows will automatically start the service.