Sunday, May 25, 2008

ASP.NET Internals Request Architecture(Lesson2)

first read the 1st lesson .

to day we will complete the Request trip:

The request and the application pool:
the request is forwarded to the application pool; each application pool is managed by an instance of the worker process “w3wp.exe”. The “w3wp.exe” runs by default under the “NetworkService” account.
This can be changed as follows: Right click on the application pool hosting your application--Properties--Identity Tab. Recall that the application pool is running by the worker – the “w3wp.exe”. So now the worker process takes over.
NetworkServiceAccount 
The worker process loads the ASP.NET ISAPI:
1-The worker process “w3wp.exe” looks up the URL of the request in order to load the correct ISAPI extension.
2-The requested resource in the URL is “Arenypage.aspx”. ISAPI extensions are IIS way to handle requests for different resources.
3-“.aspx” extension is mapped to the aspnet_isapi.dll extension.
4-The worker process passes the request to the aspnet_isapi extension.
5-The aspnet_isapi extension in turn loads the HTTP Runtime and processing of the request starts.
isapi
Note1:“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 extension.”
Note2: You can see the mappings in the IIS as follows: Right click on the Web Site-Properties-Home Directory Tab-Configuration Button-Mappings Tab. The figure below shows the mappings.
MapingEXtension

Thx Hope lesson 1 be useful for U ... tomorrow will Complete with
how the worker process loads the web application.

References
http://www.codeproject.com/KB/aspnet/aspnetrequestarchitecture.aspx
http://www.codeproject.com/KB/aspnet/aspnetviewstatepagecycle.aspx
http://www.codeproject.com/KB/aspnet/PageLifeCycle.aspx

ASP.NET Internals Request Architecture(Lesson1)

Introduction
All of us know asp.net as a high level abstractions provides for us web forms, web services… underneath these abstractions sits a very interesting and advanced architecture.
But the important question here why we need to understand this architecture?
1-    Elevates you into advanced zone.
2-    Help you to write better designed applications.
3-    Solve advanced problem that occur way below the high level asp.net use.

Zone 
Let’s go throw this advanced zone by asking important question.
How asp.net and IIS handles Requests throw this architecture?
To answer our first question let us say that a user requested the following URL://www.Areny.net/default.aspx and this request will reach “Areny Server” which has windows server 2003 and IIS 6.0.
Request 
Once the Request Reaches IIS, It is detected by http.sys Kernel Mode Driver, here we must explain first.
What is the http.sys kernel mode?
What is that it does?

Modes

Generally speaking, Windows provides two modes:
User Mode: User applications run in User Mode.
Kernel Mode: Operating system code runs in Kernel Mode.

If a user application needs to work directly with the hardware; that specific action is done by a Kernel Mode process.

“The obvious purpose of these modes is to protect the operating system components from being damaged by user applications.”

So now that we know what User Mode and Kernel Mode are?
What is the role of the http.sys kernel mode driver?
httpsys

When you create a new IIS Web Site, IIS registers the site with http.sys, which then receives any HTTP requests for any web application within the site. The http.sys functions as a forwarder, directing the http requests to the User Mode process that runs the web application.
In this case the User Mode process is the worker process running the application pool which the web application runs under. The http.sys implements a queuing mechanism by creating as many queues as there are application pools in IIS.

Following up with our example, once the request reaches “Arenyserver”, http.sys picks up the request. Let us say that “Arenyapplication” is configured to run under application pool “Arenyapplicationpool”; in this case http.sys inspects the request queue of “Arenyapplicationpool” and forwards the request to worker process under which “Arenyapplicationpool” is running under.

 

Thx Hope lesson 1 be useful for U ... tomorrow

The request is forwarded to the application pool

References
http://www.codeproject.com/KB/aspnet/aspnetrequestarchitecture.aspx
http://www.codeproject.com/KB/aspnet/aspnetviewstatepagecycle.aspx
http://www.codeproject.com/KB/aspnet/PageLifeCycle.aspx