ASP.NET Tip: When to use which Session Server

There are 3 different ways you can store session in an ASP.NET application:

  1. InProc (default mode)
  2. State Server
  3. 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:

    <sessionState mode="StateServer"

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:

    <sessionState mode="SQLServer"
      sqlConnectionString="Integrated Security=SSPI;data 
        source=SampleSqlServer;" />

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 (2)

  1. Jess Coburn says:

    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 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 state service on very busy sites actually crash.

    hope it helps.

Skip to main content