Types of Session State in ASP.NET

Session State Mode | State Provider

Soumya Patil
2 min readNov 18, 2020

InProc | In-Memory Object

StateServer | Aspnet_state.exe

SQLServer | DataBase

Custom | Custom Provider

InProc:

When the session state mode is set to InProc, the session state variable are stored on the web server memory inside the asp.net worker process. This is the default session state mode.

InProc

Advantages:

  1. Very easy to implement. All that is required is, to set, the session state mode-InProc in web.config file.
  2. Will perform best because the session state memory is kept on the web server, within the ASP.NET worker processes (w3wp.exe)
  3. Suitable for web application hosted on a single server.
  4. Objects can be added without serialization.

Disadvantages:

  1. Session state data is lost, when the worker process or applicationpool is recycled.
  2. Not suitable for webforms and webgardens.
  3. Scalability could be an issue.

StateServer Mode:

When the session state mode is set to StateServer, the session state variables are stored in a process, called as asp.net state service. This process is different from the asp.net worker process. The asp.net state service can be present on a web server or a dedicated machine.

State Server

Advantages:

  1. ASP.NET worker process independent. Survives worker process restart.
  2. Can be used with web farms and web gardens.Suitable for web application hosted on a single server.
  3. State server offers more scalability than InProc.

Disadvantages:

  1. StateServer is slower than InProc.
  2. Complex objects, need to be serialized and deserialized.
  3. If the StateServer, is on a dedicated machine, and if the server goes down all the sessions are lost.

SQLServer:

When the session state mode is set to SQLServer, the session state variables are stored in a SQLServer database.

SQL Server

Advantages:

  1. SQLServer is the most reliable option. Survives worker process recycling and SQL Server restarts.
  2. Can be used with web farms and web gardens.
  3. More scalable than State server and InProc session state modes.Objects can be added without serialization.

Disadvantages:

  1. Slower than StateServer and InProc session state modes.
  2. Complex object, need to be serialized and deserialized.

Note:

Web Garden: Web application deployed on a server with multiple processes.

Web Farm: Web application deployed on muitiple server.

--

--

Soumya Patil
Soumya Patil

No responses yet