Friday, July 9, 2010

ASP.NET State Service

Issue: With load balanced application servers, you have to refer to a state server.

Solution: Windows Server 2003 comes with a service "ASP.NET State Service".  It is set to manual by default.  You need to do a few things to configure it to be used as a central State Server.
  1. click start - services.msc - ok
  2. find "ASP.NET State Service" change its startup type to automatic and start it
  3. open command prompt
  4. netstat -ano | find "42424" | RESPONSE TCP    127.0.0.1:42424        0.0.0.0:0              LISTENING       5640
  5. run REGEDIT
  6. NAVIGATE to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\aspnet_state\Parameters
  7. Change "AllowRemoteConnection" Value Data from 0 to 1
  8. Restart the service
  9. Re-run the command from step 4
  10. netstat -ano | find "42424" | RESPONSE TCP    0.0.0.0:42424          0.0.0.0:0              LISTENING       1240
  11. Now that it is listening on 0.0.0.0 it means it can receive requests from other servers.

Then of course - inside your app's web.config file you'll need to add two things:

1. Machine Key: made up of a validation key & a decryption key.
we recommend using Development Now to generate the string.

2. reference to your new state server you configured above
<sessionState mode="StateServer"
stateConnectionString="tcpip=SERVERNAME.DOMAIN.LOCAL:42424"
cookieless="false"
timeout="20"/>