ASP.NET Complete Life Cycle
page 2 of 3
by Srinivas Jadhav
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 18638/ 32

Application Domain

Application Domain provides isolation between different applications for global variables and allows each application to be unloaded separately.

Multiple Application Domains can run in a Single Process.

Why Isolation?

Single process can have multiple threads, memory leak, out-of-bound memory access, null object referencing, etc. If one of the applications crashes because of these, then all the application crashes; therefore, Isolation of application is required.


An instance of a class named HostingEnvironment is created which resides in Application Domain.

Once the Application Domain is created and HostingEnvironment object is instantiated, Http requests are passed to an instance of the HttpRuntime class. HttpRuntime object examines the request and figures out which application it was sent to (i.e. virtual directory). It the uses HttpApplicationFactory to either find or create an HttpApplication object to process the request.

ASP.NET creates and initializes the core objects such as HttpContext, HttpRequest and HttpResponse.

After all the core objects are initialized, the application is started by creating an instance of the HttpApplication class. HttpApplication holds a collection of Http module objects

Application is started by creating an instance of the HttpApplication class. If the application contains Global.asax, it overrides the Global.asax file, which is derived from the HttpApplication.

The first time an ASP.NET page or process is requested in an application, a new instance of HttpApplication is created. To maximize performance, HttpApplication instances might be reused for multiple requests.

An instance of HttpApplication processes only one request at a time.

The following are the events which are called during the application life cycle.

1. Application_Start: It is called when the first resource in an ASP.NET application is requested.

2. Application_event:  It is called at the appropriate time during the application life cycle.

Some of the Application events are as follows.

Application_BeginRequest: Whenever ASP.NET responds to the Request, it will be the first to occur in the Http Pipeline.


Listing 1

public event EventHandler BeginRequest; 

Application_AuthenticateRequest: Occurs whenever the identity of the user has to be established.


Listing 2

public event EventHandler AuthenticateRequest;

Application_AuthorizeRequest: Occurs whenever the identity of the user has been verified.


Listing 3

public event EventHandler AuthorizeRequest;

Application_Error: Occurs when ever the unhandled exception is thrown.


Listing 4

public event EventHandler Error;

Application_EndRequest: Whenever ASP.NET responds to the Request, it will be the last to occur in the Http Pipeline chain.


Listing 5

public event EventHandler EndRequest;

3. HttpApplication.Init: called once for every instance of the HttpApplication class.

4. Application_End: Called once per lifetime of the application before the application is unloaded.

View Entire Article

User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024  |  Page Processed at 2024-05-24 1:33:35 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search