---
title: "Session-State in ASP.NET"  
description: "ASP.NET provides three distinct ways to store session data for your application: in-process session state, out-of-process session state as a Windows s"  
author: "Amit Singh"  
published: 2010-11-06  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/47/session-state-in-asp-dot-net  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 2 minutes  

---

# Session-State in ASP.NET

ASP.NET provides three distinct ways to store [session data](https://www.mindstick.com/forum/158231/how-can-session-data-be-encrypted-and-what-are-the-benefits-and-drawbacks-of-doing-so) for [your application](https://www.mindstick.com/forum/34702/please-tell-me-what-is-cross-site-scripting-and-how-is-it-harmful-for-your-application): in-process [session state](https://www.mindstick.com/articles/42/session-state-in-asp-dot-net), out-of-process session state as a Windows service, and out-of-process session state in a SQL [Server database](https://www.mindstick.com/forum/155643/how-to-create-sql-server-database-in-google-cloud). Each has it advantages.

##### 1.In-process session-state mode

Limitations: \
* When using the in-process session-state mode, session-state data is lost if aspnet_wp.exe or the [application domain](https://www.mindstick.com/interview/1775/explain-the-application-domain-in-dot-netframework) restarts. \
* If you enable Web garden mode in the < processModel > element of the application's Web.config file, do not use in-process session-state mode. Otherwise, random [data loss](https://www.mindstick.com/interview/34105/how-do-you-safely-overwrite-a-file-without-data-loss-if-something-fails) can occur. \
Advantage:\
* in-process session state is by far the fastest solution. If you are storing only small amounts of volatile data in session state, it is recommended that you use the in-process provider.\

##### 2. The State Server

It simply stores session state in memory when in out-of-proc mode. In this mode the [worker process](https://www.mindstick.com/forum/496/does-asp-debugging-work-in-iis-6-0-worker-process-isolation-mode) talks directly to the State Server\
\

##### 3. SQL mode

It session states are stored in a [SQL Server](https://www.mindstick.com/articles/12999/what-is-table-valued-function-in-sql-server) database and the worker process talks directly to SQL. The ASP.NET worker processes are then able to take advantage of this simple storage service by serializing and saving (using .NET [serialization](https://www.mindstick.com/articles/11917/serialization-in-java) services) all objects within a client's Session collection at the end of each Web request Both these out-of-process solutions are useful primarily if you scale your [application across multiple](https://www.mindstick.com/interview/34157/how-do-you-scale-a-signalr-application-across-multiple-servers-e-g-using-redis-backplane) processors or multiple computers, or where data cannot be lost if a server or process is restarted. \
\

---

Original Source: https://www.mindstick.com/blog/47/session-state-in-asp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
