Background
We all know that the web uses the HTTP protocol and that the HTTP protocol is a stateless protocol, in other words when a client sends a request to the server, an instance of the page is created and the page is converted to HTML format and then the server returns the response and then the instance of the page and the value of the control is destroyed. So if we have a requirement to store the value of controls then a State Management technique is used.
Introduction
Application State is a state management technique. Application State is stored in the memory of the the server and is faster than storing and retrieving information in a database. Session sate is specific for a single user session, but Application State is for all users and sessions. Application State does not have a default expiration period. When we close the worker process the application object will be lost. Technically the data is shared amongst users by a HTTPApplcationState class and the data can be stored here in a key/value pair. It can also be accessed using the application property of the HTTPContext class.
Application State Life Cycle
Step 1: When the Browser sends a request to the web server and the server receives the request it first checks the extension to determine whether or not it is ISAPI because this request can only be handled by the ISAPI extension; if the extension is different then the request is handled by the server itself.

Step 2: After receiving the request the Application Manager creates an application domain. In the application domain an instance of the class HostingEnvironment is created that provides access to information about all application resources.

Step 3: After creating the application domain, ASP.NET initializes the basic objects as HTTPContext, HTTPRequest and HTTPResponse. HTTPContext holds objects to the specific application request as HTTPRequest and HTTPResponse.HTTPRequest contains all the information regarding the current request like cookies, browser information and so on and the HTTPResponse contains the response that is sent to the client.
Step 4: Here all the basic objects are being initialized and the application is being started with the creation of the HTTPApplication class.

Step 5: Then events are executed by the HTTPApplication class for any specific requirement. Here is a list of events:

Global.asax file: the Global.asax file is used for handling application events or methods. It always exists in the root level. Events are one of the following of the 2 types in the Global application:
- Events that will be raised on a certain condition.
- Events that will be raised on every request.
The application will be started only once; if 10 users send a request then 10 user sessions are created. The events of the Global.asax file are:
- Application_Start() : This method is invoked initially when first application domain is created.
- Session_Start() : This method is called every time a session is start.
- Application_BeginRequest() : After an application has started the first method Application_BeginRequest() is executed for every user.
- Application_AuthenticateRequest() : It checks to determine whether or not the user is valid.
- Application_Error() : Whenever an unhandled exception occurs then this event will be called.
- Session_End() : When a user session is ended and all the data related to a specific user is cleared then the Session_End() event is called.
- Application_End() : This method is called before the application ends. This can take place if IIS is restarted or the application domain is changing.
- Application_Disposed() : This event is called after the application will be shut down and the .NET GC is about to reclaim the memory it occupies. Although this is very late to perform any clean-up but we can use it for safety purposes.








Kanhaiya KumawatPosted Nov 5, 2019, 9:04 PM
Really amazing artical dear
Altrin rejoPosted Oct 31, 2016, 8:36 AM
Amazing Article
Deepak PorwalPosted Jan 23, 2015, 8:13 AM
Nice article ...