{"id":78358,"date":"2025-08-05T16:50:30","date_gmt":"2025-08-05T16:50:30","guid":{"rendered":"http:\/\/bangla.sitestree.com\/?p=78358"},"modified":"2025-08-05T21:50:45","modified_gmt":"2025-08-05T21:50:45","slug":"application-state-variables-in-c-net","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=78358","title":{"rendered":"Application State Variables in C#.net"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<p>Here\u2019s a <strong>clear, copyright-free explanation<\/strong> of <strong>Application State Variables in C#.NET<\/strong>, ideal for blogs, Facebook pages, or classroom notes.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83c\udf10 Application State Variables in C#\/.NET<\/h1>\n\n\n\n<p><strong>Application State<\/strong> in ASP.NET is a way to store <strong>global data<\/strong> that is <strong>shared by all users<\/strong> across the entire web application.<\/p>\n\n\n\n<p>It is commonly used to store settings, counters, configuration values, or cache-like data that doesn\u2019t change per user.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udce6 What is Application State?<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A <strong>server-side<\/strong> storage mechanism.<\/li>\n\n\n\n<li>Stored in <strong>memory<\/strong> on the web server.<\/li>\n\n\n\n<li>Accessible using the <code>Application<\/code> object.<\/li>\n\n\n\n<li><strong>Shared across all sessions and users<\/strong>.<\/li>\n\n\n\n<li>Exists for the lifetime of the application (until the server restarts or the application is recycled).<\/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\">\ud83d\udd27 Syntax to Use Application State<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 Add or Set a Variable<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>Application&#91;\"SiteTitle\"] = \"My Awesome Website\";\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 Read a Variable<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>string title = Application&#91;\"SiteTitle\"].ToString();\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 Remove a Variable<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>Application.Remove(\"SiteTitle\");\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 Clear All Application Variables<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>Application.Clear();\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd10 Thread Safety: Application.Lock and Application.UnLock<\/h2>\n\n\n\n<p>Since Application state is <strong>shared<\/strong>, you must be careful when multiple users are reading\/writing the same data.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udd12 Lock and Unlock Example<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>Application.Lock();\nApplication&#91;\"VisitorCount\"] = (int)Application&#91;\"VisitorCount\"] + 1;\nApplication.UnLock();\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>Lock()<\/code> prevents other users from modifying the data at the same time.<\/li>\n\n\n\n<li><code>UnLock()<\/code> releases the lock so others can access it.<\/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\">\ud83e\udde0 Common Use Cases<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Use Case<\/th><th>Example<\/th><\/tr><\/thead><tbody><tr><td>Global site settings<\/td><td>Application[&#8220;Theme&#8221;] = &#8220;Dark&#8221;<\/td><\/tr><tr><td>Visitor counter<\/td><td>Application[&#8220;VisitorCount&#8221;] = 100<\/td><\/tr><tr><td>App-wide configuration<\/td><td>Application[&#8220;MaxUsers&#8221;] = 50<\/td><\/tr><tr><td>Read-only cached data<\/td><td>Application[&#8220;CountriesList&#8221;] = GetCountries()<\/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\udcdd Notes<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Application state is <strong>not persisted<\/strong>\u2014it&#8217;s lost when the application pool is recycled or the server restarts.<\/li>\n\n\n\n<li>Not suitable for <strong>user-specific<\/strong> data (use <code>Session<\/code> instead).<\/li>\n\n\n\n<li>Available only in <strong>ASP.NET Web Forms or MVC<\/strong> (not in ASP.NET Core).<\/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\">\u26a0\ufe0f Not Available in ASP.NET Core<\/h2>\n\n\n\n<p>ASP.NET Core does not support <code>Application[]<\/code> state directly.<\/p>\n\n\n\n<p>Instead, you can use:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Singleton services<\/strong> via dependency injection<\/li>\n\n\n\n<li><strong>IMemoryCache<\/strong> for caching<\/li>\n\n\n\n<li><strong>IOptions<\/strong> for configuration<\/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\">\u2705 Summary<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Feature<\/th><th>Application State<\/th><\/tr><\/thead><tbody><tr><td>Scope<\/td><td>Shared across all users and sessions<\/td><\/tr><tr><td>Lifetime<\/td><td>Until app restart or recycle<\/td><\/tr><tr><td>Use for<\/td><td>Global, read-only, or low-frequency data<\/td><\/tr><tr><td>Access object<\/td><td><code>Application[\"Key\"]<\/code><\/td><\/tr><tr><td>Thread safety<\/td><td>Use <code>Lock()<\/code> and <code>UnLock()<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>Let me know if you&#8217;d like a <strong>sample project<\/strong>, <strong>PDF summary<\/strong>, or <strong>diagram<\/strong> for visual learners!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 used to store settings, counters, &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=78358\">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,1977],"tags":[],"class_list":["post-78358","post","type-post","status-publish","format-standard","hentry","category-c-misc","category-web-programming-in-c","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":78360,"url":"http:\/\/bangla.sitestree.com\/?p=78360","url_meta":{"origin":78358,"position":0},"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":78352,"url":"http:\/\/bangla.sitestree.com\/?p=78352","url_meta":{"origin":78358,"position":1},"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":78354,"url":"http:\/\/bangla.sitestree.com\/?p=78354","url_meta":{"origin":78358,"position":2},"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":70305,"url":"http:\/\/bangla.sitestree.com\/?p=70305","url_meta":{"origin":78358,"position":3},"title":"Allow Page Access only to the Logged in Users #.Net Web Applications","author":"Author-Check- Article-or-Video","date":"September 1, 2021","format":false,"excerpt":"Brought from our old site: http:\/\/salearningschool.com\/displayArticle.php?table=Articles&articleID=1349&title=Allow%20Page%20Access%20only%20to%20the%20Logged%20in%20Users Allow Page Access only to the Logged in Users It's common across many sites that you allow certain pages of your site only to the logged in users. Here, I am providing a simple way to do that in your site The main idea\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":22847,"url":"http:\/\/bangla.sitestree.com\/?p=22847","url_meta":{"origin":78358,"position":4},"title":"Entity Framework and MVC Application Demo in ASP.Net and C Sharp #Root #By Sayed Ahmed","author":"Author-Check- Article-or-Video","date":"March 21, 2021","format":false,"excerpt":"Entity Framework and MVC Application Demo in ASP.Net and C Sharp [youtube http:\/\/www.youtube.com\/watch?v=3sGS7-z3WcU?feature=player_detailpage&w=640&h=360] From: http:\/\/sitestree.com\/?p=1514 Categories:Root, By Sayed AhmedTags: Post Data:2014-09-16 06:37:31 Shop Online: https:\/\/www.ShopForSoul.com\/ (Big Data, Cloud, Security, Machine Learning): Courses: http:\/\/Training.SitesTree.com In Bengali: http:\/\/Bangla.SaLearningSchool.com http:\/\/SitesTree.com 8112223 Canada Inc.\/JustEtc: http:\/\/JustEtc.net (Software\/Web\/Mobile\/Big-Data\/Machine Learning) Shop Online: https:\/\/www.ShopForSoul.com\/ Medium: https:\/\/medium.com\/@SayedAhmedCanada","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":65677,"url":"http:\/\/bangla.sitestree.com\/?p=65677","url_meta":{"origin":78358,"position":5},"title":"Debugging in .Net, (XML Web Services) #Misc .Net","author":"Author-Check- Article-or-Video","date":"July 11, 2021","format":false,"excerpt":"Brought from: http:\/\/salearningschool.com\/displayArticle.php?table=Articles&articleID=1117&title=Debugging%20in%20.Net,%20(XML%20Web%20Services) Just listing some related notes. Tools: DbgClr -GUI Based, CorDbg - command line based You can use the debug menu. Start, Step Into, Step Over, New Breakpoint options - as available in most Good to great IDEs for debugging Watch Window: Check the values of variables and\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/78358","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=78358"}],"version-history":[{"count":1,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/78358\/revisions"}],"predecessor-version":[{"id":78359,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/78358\/revisions\/78359"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=78358"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=78358"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=78358"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}