ASP.NET Tip: When to use which Session Server
There are 3 different ways you can store session in an ASP.NET application:
- InProc (default mode)
- State Server
- SQL Server
InProc means we store the data in the same process (in memory) on the web server, in the worker process. This has some distinct advantages in that it is faster since everything is in the same process. It also means you can store anything in session as you don’t have to worry about serializing the data.
State Server is a process that runs separate from the worker process. This can run on the same machine or on a different machine. The advantage to this one is that if the worker process crashes, you don’t lose your session. Also, you can do some sharing of session across multiple servers in the web farm. To enable using State Server, you add the following configuration setting:
<configuration>
<system.web>
<sessionState mode="StateServer"
stateConnectionString="tcpip=SampleStateServer:42424"
cookieless="false"
timeout="20"/>
</system.web>
</configuration>
SQL Server mode is similar to State Server except that the data is stored in a SQL Server database. This is the best option if you are expecting heavy use as SQL is designed to handle large loads of requests. To enable SQL Server, you add the following configuration setting:
<configuration>
<system.web>
<sessionState mode="SQLServer"
sqlConnectionString="Integrated Security=SSPI;data
source=SampleSqlServer;" />
</system.web>
</configuration>
For the last two choices, it is best to encrypt the connection string for security purposes. For steps to do that, check out Encrypting Configuration Information Using Protected Configuration.
There is another method, but it is creating your own provider. You can get more information on doing that at Implementing a Session-State Store Provider.
Comments
Anonymous
October 02, 2008
PingBack from http://www.easycoded.com/aspnet-tip-when-to-use-which-session-server/Anonymous
October 03, 2008
Just FYI, a 10% decrease in performance is expected when going from inproc to state service and a 20% from inproc to sql server. This is a rule of thumb and can vary ofcourse. We're seeing state server becoming increasing popular with asp.net hosted sites and would recommend it over inproc because the performance hit really isn't noticeable. Ofcourse you do want to be be careful just how much data you'll store in session state though as we've seen the asp.net state service on very busy sites actually crash. hope it helps.