In this article, we will show you how can we implement “state server” session state management technique in asp.net
Bellow are steps for implementing “State Server” session management technique.
- Add configuration in of Web.Config.
<sessionState mode=”StateServer” stateConnectionString=”tcpip=127.0.0.1:42424″/>
Here, mode=”StateServer” means session mode is “State Server”. Other modes are inproc, SQL server & custom.
stateConnectionString=”tcpip=127.0.0.1:42424″ means session state windows service is running on 127.0.0.1 (this is same machine where I am running my application as well as service. If you are running windows service on other machine then put that machines IP) on port 42424 (this is default port on which service runs. This can bechanged in registry).
- Starting “StateServer” windows service
Go to services (gor to Run => services.msc) & find “ASP.NET State Service”.
Change startup type of“ASP.NET State Service”to “Automatic” & start the service.
This configuration is enough if you have state server on same machine.
You might get bellow error if you are using other machine for storing state.
“Unable to make the session state request to the session state server. Please ensure that the ASP.NET State service is started and that the client and server ports are the same. If the server is on a remote machine, please ensure that it accepts remote requests by checking the value of HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\aspnet_state\Parameters\AllowRemoteConnection. If the server is on the local machine, and if the before mentioned registry value does not exist or is set to 0, then the state server connection string must use either ‘localhost’ or ’127.0.0.1′ as the server name.”
To solve this error follow bellow steps
- Go to machine where windows service is running.
- Go to registry (Go to Run => regedit)
- Go to this path -> “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\aspnet_state\Parameters\AllowRemoteConnection”
- Change Value of parameter “AllowRemoteConnection” from 0 to 1.
Here you also change port number as well by changing Value of “PORT” parameter.
- Now restart windows service.
Hope fully after doing this error will be gone & you will be able to implement “StateServer” session management technique successfully in ASP.NET.