State Management in ASP.NET
Prove you're a Dev Guru! Take the test now!
ASP.NET is a powerful development platform for web applications, based on Microsoft .NET Framework. Microsoft .NET Framework is a software framework containing coded libraries that provide solutions to common programming problems. Web pages in ASP.NET are based on the HTTP protocol.
HTTP is a 'stateless' protocol, which means that a new instance of web page class is created each time the page is posted to the server. All information associated with the web page and the controls on the web page would be lost for each round trip. For instance, if a user inputs some value on the web page, all those input values will get lost in a round trip from browser to the web server.
To overcome this drawback, ASP.NET includes various state management techniques to preserve data. State management is the process of maintaining state and data of pages, throughout multiple requests for the same or different pages.
ASP.NET offers two types of state management:
1. Server-side state management
This state management feature uses resources on the web server. Below are different server-side state management techniques used by ASP.NET.
Application state
ASP.NET enables you to store information using application state, which is an instance of HttpApplicationState class. Application state is a mechanism for storing global information that is available at all the pages.
The Application state instance is automatically created when a user makes a first request to the web application, and all subsequent users share this state object. Application state exposes the key/value dictionary to store information. Consider the following code for saving and retrieving data from Application state:
//Store data in application state
Application["MyApplicationData"] = "my application data";
//Retrieve data from application state
string myData = Application["MyApplicationData"].ToString();
Recommended Articles
blog comments powered by Disqus
