Sunday, January 4, 2009

ASP.NET Internals Part 1

ASP.NET Internals Part 1

To start with my first blog posting I thought of to start with Application Life Cycle.

1. The life cycle of the ASP.NET start with a request sent by a browser to the web server. When a Web server receives a request, it examines the file-name extension of the requested file, determines which ISAPI extension should handle the request, and then passes the request to the appropriate ISAPI extension.

Basically ASP.NET has its own ISAPI extension. Once ASP.NET is installed, it installs its own ISAPI extension (aspnet_isapi.dll) and adds the mapping into IIS. IIS maps various extensions to its ISAPI extensions. You can see the mappings in IIS as follows: right click on the
Virtual directory àPropertiesàHome Directory tabàConfiguration button-Mappings tab. The figure below shows the mappings


















2. When ASP.NET receives the first request for any resources. It creates an application domain and within a application domain, an instance of the class named HostingEnvironment is created, which provides access to information about the application such as the name of the folder where the application is stored

Basically application domain is used to isolate applications from one another. This is the same way an operating system process works. The separation is required so that applications do not affect one another. This separation is achieved by making sure than any given unique virtual address space runs exactly one application and scopes the resources for the process or application domain using that addess space.



3. For each request ASP.NET initialize the core objects
a. HttpContext : holds the information’s that are specific to the current application request example you can access the HttpContext object as follows
Context.IsCustomErrorEnabled, Context.IsDebuggingEnabled, etc
b. HttpRequest: it enables to read the http values sent by a client during web request
c. HttpRespose: holds the information that is sent back to the client, including all rendering output and cookies


4. After all core application objects have been initialized, the application is started by creating an instance of the HttpApplication class. One instances of the HttpApplication class is used to process many request in its lifetime. However, it can process only one request at a time. Thus, member variables can be used to store per-request data.
The application events are raised in the following order:

A. BeginRequest
B. AuthenticateRequest
C. PostAuthenticateRequest
D. AuthorizeRequest
E. PostAuthorizeRequest
F. ResolveRequestCache
G. PostResolveRequestCache
H. PostMapRequestHandler
I. AcquireRequestState
J. PostAcquireRequestState
K. PreRequestHandlerExecute
The event handler is executed.

L. PostRequestHandlerExecute
M. ReleaseRequestState
N. PostReleaseRequestState
After the PostReleaseRequestState event is raised, any existing response filters will filter the output.

O. UpdateRequestCache
P. PostUpdateRequestCache
Q. LogRequest.
This event is supported in IIS 7.0 Integrated mode and at least the .NET Framework 3.0

R. PostLogRequest
This event is supported IIS 7.0 Integrated mode and at least the .NET Framework 3.0

S. EndRequest