{"id":78356,"date":"2025-08-05T16:45:48","date_gmt":"2025-08-05T16:45:48","guid":{"rendered":"http:\/\/bangla.sitestree.com\/?p=78356"},"modified":"2025-08-05T21:50:45","modified_gmt":"2025-08-05T21:50:45","slug":"modes-of-session-state-management","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=78356","title":{"rendered":"Modes of Session State Management"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<p><strong>By AI:<\/strong><\/p>\n\n\n\n<p>Here are the <strong>5 modes to store Session State in ASP.NET<\/strong>, each with its own storage location and behavior. This is especially useful for configuring <strong>ASP.NET (Framework) Web Forms or MVC applications<\/strong> \u2014 though some modes also apply to <strong>ASP.NET Core<\/strong> with slight differences.<\/p>\n\n\n\n<p>You can copy and share this content freely on your blog or Facebook. \u2705<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\udd10 5 Session State Modes in ASP.NET<\/h1>\n\n\n\n<p>Session state helps store <strong>user-specific data<\/strong> (like login info, preferences, shopping cart) across multiple requests and pages. ASP.NET provides <strong>five storage modes<\/strong> for session state, configured in <code>web.config<\/code>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">1\ufe0f\u20e3 <strong>InProc (In-Process)<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Default mode<\/strong>: Session data is stored <strong>in memory on the web server<\/strong>.<\/li>\n\n\n\n<li>Fastest option because it doesn\u2019t involve external storage.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;sessionState mode=\"InProc\" \/&gt;\n<\/code><\/pre>\n\n\n\n<p><strong>Pros:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Fastest<\/li>\n\n\n\n<li>Easy to implement<\/li>\n<\/ul>\n\n\n\n<p><strong>Cons:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Data is lost if the server restarts<\/li>\n\n\n\n<li>Not suitable for web farms (multi-server setups)<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">2\ufe0f\u20e3 <strong>StateServer (Out-of-Process)<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Stores session data in a separate <strong>ASP.NET State Service<\/strong> (runs as a Windows service).<\/li>\n\n\n\n<li>Can be on the same machine or another server.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;sessionState mode=\"StateServer\" stateConnectionString=\"tcpip=localhost:42424\" \/&gt;\n<\/code><\/pre>\n\n\n\n<p><strong>Pros:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>More durable than InProc<\/li>\n\n\n\n<li>Supports web farms (multiple servers)<\/li>\n<\/ul>\n\n\n\n<p><strong>Cons:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Slower than InProc (uses serialization and networking)<\/li>\n\n\n\n<li>Requires running the state service<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">3\ufe0f\u20e3 <strong>SQLServer<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Stores session data in a <strong>SQL Server database<\/strong>.<\/li>\n\n\n\n<li>Great for <strong>durability and scalability<\/strong>.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;sessionState mode=\"SQLServer\" sqlConnectionString=\"data source=YourDBServer;user id=sa;password=pass\" \/&gt;\n<\/code><\/pre>\n\n\n\n<p><strong>Pros:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Highly durable (survives server restarts and crashes)<\/li>\n\n\n\n<li>Works well in web farms<\/li>\n<\/ul>\n\n\n\n<p><strong>Cons:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Slower due to database access<\/li>\n\n\n\n<li>Requires database setup and maintenance<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">4\ufe0f\u20e3 <strong>Custom<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You can define your own <strong>custom session state provider<\/strong> (e.g., Redis, MongoDB, distributed cache).<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;sessionState mode=\"Custom\" customProvider=\"MyProvider\"&gt;\n  &lt;providers&gt;\n    &lt;add name=\"MyProvider\" type=\"YourNamespace.YourCustomProvider\" \/&gt;\n  &lt;\/providers&gt;\n&lt;\/sessionState&gt;\n<\/code><\/pre>\n\n\n\n<p><strong>Pros:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Flexible<\/li>\n\n\n\n<li>Can integrate modern distributed caching solutions<\/li>\n<\/ul>\n\n\n\n<p><strong>Cons:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Requires more development work<\/li>\n\n\n\n<li>Performance and reliability depend on your implementation<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">5\ufe0f\u20e3 <strong>Off<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Disables session state entirely.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;sessionState mode=\"Off\" \/&gt;\n<\/code><\/pre>\n\n\n\n<p><strong>Use case:<\/strong> For <strong>static content<\/strong> or pages that don\u2019t need session state (improves performance).<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd01 Summary Table<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Mode<\/th><th>Stored In<\/th><th>Speed<\/th><th>Supports Web Farm<\/th><th>Survives App Restart<\/th><th>Notes<\/th><\/tr><\/thead><tbody><tr><td>InProc<\/td><td>Server Memory<\/td><td>\u2705 Fastest<\/td><td>\u274c No<\/td><td>\u274c No<\/td><td>Default, simple apps<\/td><\/tr><tr><td>StateServer<\/td><td>Windows Service<\/td><td>\u26a0 Medium<\/td><td>\u2705 Yes<\/td><td>\u2705 Yes<\/td><td>Needs external service<\/td><\/tr><tr><td>SQLServer<\/td><td>SQL Database<\/td><td>\u26a0 Slower<\/td><td>\u2705 Yes<\/td><td>\u2705 Yes<\/td><td>Good for large-scale apps<\/td><\/tr><tr><td>Custom<\/td><td>Your choice<\/td><td>\u26a0 Varies<\/td><td>\u2705 Yes<\/td><td>\u2705 Depends<\/td><td>For custom cache\/storage<\/td><\/tr><tr><td>Off<\/td><td>\u2014<\/td><td>\u2705 N\/A<\/td><td>\u2705 Yes<\/td><td>\u2705 Yes<\/td><td>When session isn&#8217;t needed<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd27 How to Set Session Mode in <code>web.config<\/code><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;configuration&gt;\n  &lt;system.web&gt;\n    &lt;sessionState mode=\"InProc\" timeout=\"20\" \/&gt;\n  &lt;\/system.web&gt;\n&lt;\/configuration&gt;\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>Let me know if you want a <strong>code example<\/strong>, <strong>diagram<\/strong>, or <strong>PDF cheat sheet<\/strong> for these session modes!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>By AI: Here are the 5 modes to store Session State in ASP.NET, each with its own storage location and behavior. This is especially useful for configuring ASP.NET (Framework) Web Forms or MVC applications \u2014 though some modes also apply to ASP.NET Core with slight differences. You can copy and share this content freely on &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=78356\">Continue reading<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1973,1,1977],"tags":[],"class_list":["post-78356","post","type-post","status-publish","format-standard","hentry","category-c-misc","category-root","category-web-programming-in-c","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":78352,"url":"http:\/\/bangla.sitestree.com\/?p=78352","url_meta":{"origin":78356,"position":0},"title":"State in .Net (C#, ASP.Net)","author":"Sayed","date":"August 5, 2025","format":false,"excerpt":"From AI: Certainly! Here's a copyright-free, blog and Facebook-ready version of the explanation on State Management in C#\/.NET. You can copy, paste, and share this freely on your blog, website, or social media. No attribution is required (but you're welcome to add your name or page if you like). \ud83c\udf10\u2026","rel":"","context":"In &quot;C# - Misc&quot;","block_context":{"text":"C# - Misc","link":"http:\/\/bangla.sitestree.com\/?cat=1973"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":78358,"url":"http:\/\/bangla.sitestree.com\/?p=78358","url_meta":{"origin":78356,"position":1},"title":"Application State Variables in C#.net","author":"Sayed","date":"August 5, 2025","format":false,"excerpt":"Here\u2019s a clear, copyright-free explanation of Application State Variables in C#.NET, ideal for blogs, Facebook pages, or classroom notes. \ud83c\udf10 Application State Variables in C#\/.NET Application State in ASP.NET is a way to store global data that is shared by all users across the entire web application. It is commonly\u2026","rel":"","context":"In &quot;C# - Misc&quot;","block_context":{"text":"C# - Misc","link":"http:\/\/bangla.sitestree.com\/?cat=1973"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":78360,"url":"http:\/\/bangla.sitestree.com\/?p=78360","url_meta":{"origin":78356,"position":2},"title":"Data Types  in Application and Session State Variables with examples","author":"Sayed","date":"August 5, 2025","format":false,"excerpt":"Here's a clear and blog\/Facebook-ready answer to: \u2753 What Type of Data Can You Store in Application State and Session State Variables in ASP.NET? In ASP.NET, both Application State and Session State are used to store data on the server side \u2014 but they serve different purposes and scopes. Below\u2026","rel":"","context":"In &quot;C# - Misc&quot;","block_context":{"text":"C# - Misc","link":"http:\/\/bangla.sitestree.com\/?cat=1973"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":78362,"url":"http:\/\/bangla.sitestree.com\/?p=78362","url_meta":{"origin":78356,"position":3},"title":"Cookies in C#","author":"Sayed","date":"August 5, 2025","format":false,"excerpt":"By AI: Here\u2019s a clear, blog- and Facebook-ready explanation of Cookies in C# (ASP.NET) with their pros and cons, including examples. You can freely copy, share, or repost it anywhere. \ud83c\udf6a Cookies in C# ASP.NET \u2013 Pros and Cons In web development with ASP.NET, cookies are used to store small\u2026","rel":"","context":"In &quot;C# - Misc&quot;","block_context":{"text":"C# - Misc","link":"http:\/\/bangla.sitestree.com\/?cat=1973"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":78354,"url":"http:\/\/bangla.sitestree.com\/?p=78354","url_meta":{"origin":78356,"position":4},"title":"Client and Server Side State Management in C# (ASP.Net)","author":"Sayed","date":"August 5, 2025","format":false,"excerpt":"By AI: Here\u2019s a copyright-free, blog\/Facebook-friendly explanation of Client-side and Server-side State Management in C#\/.NET, along with techniques under each category. You can freely copy and use it. \ud83c\udf0d Client-side vs Server-side State Management in C#\/.NET In C# and .NET applications\u2014especially in web development like ASP.NET\u2014state management helps maintain data\u2026","rel":"","context":"In &quot;C# - Misc&quot;","block_context":{"text":"C# - Misc","link":"http:\/\/bangla.sitestree.com\/?cat=1973"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":78364,"url":"http:\/\/bangla.sitestree.com\/?p=78364","url_meta":{"origin":78356,"position":5},"title":"Query Strings in C#","author":"Sayed","date":"August 5, 2025","format":false,"excerpt":"Here\u2019s a complete, copyright-free guide to Query Strings in C# \/ ASP.NET, including definition, examples, use cases, limitations, performance, and security. You can freely copy-paste this on your blog or Facebook page. \ud83d\udd17 Query String in C# ASP.NET \u2013 Complete Guide \ud83d\udcd8 Definition A query string is a part of\u2026","rel":"","context":"In &quot;C# - Misc&quot;","block_context":{"text":"C# - Misc","link":"http:\/\/bangla.sitestree.com\/?cat=1973"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/78356","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=78356"}],"version-history":[{"count":1,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/78356\/revisions"}],"predecessor-version":[{"id":78357,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/78356\/revisions\/78357"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=78356"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=78356"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=78356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}