I. Processing Between IIS and ASP. NET
IIS 5 is not discussed here. It has been basically eliminated in the actual production environment. Let's look at ASP.net request processing process 1 of IIS 6 (the integration mode of IIS 7 is not discussed for the moment ).
Figure 1
First, we access the website through a URL. At this time, we find the IP address of the host through DNS resolution, and the http in the host operating system (only for Windows. the sys component listens to this request.
Note: To prevent users' applications from accessing or modifying critical operating system data, windows provides two processor access modes: User Mode and Kernel Mode ). Generally, the User program runs in User mode, while the operating system code runs in Kernel Mode. The Kernel Mode code allows access to all system memory and all CPU commands.
Then, in User Mode, http. sys receives an http request based on aspx, And then it checks which Application Pool the Request-based Application belongs to based on Metabase in IIS. If the Application Pool does not exist, it is created. Otherwise, the request is directly sent to the Queue of the corresponding Application Pool. Each Application Pool corresponds to a Worker Process: w3wp.exe. The Application Pool and worker process Mapping are maintained in IIS Metabase. Based on such a ing, the WAS (Web Administrative service) transmits requests that exist in an Application Pool Queue to the corresponding worker process (if not, such a process is created ). When the worker process is initialized, ASP. net isapi is loaded.
At the same time, inside w3wp.exe, ASP. NET is added to IIS in the form of iis isapi extension. In fact, both ASP and PHP are configured in the same way. (PHP adopts two configuration methods in IIS, in addition to the iis isapi extension method and CGI method, the system administrator can select the PHP program execution method). Therefore, the client will first process the HTTP request to IIS through IIS, then, IIS handles HTML static Web Pages Based on the required content type. If not, it assigns them to their respective iis isapi extension based on the required content type; if the requested content type is ASP. NET. net iis isapi Extension, that is, aspnet_isapi.dll. During request processing, the first five steps of the ISAPI filter (ISAPI The Filter is similar to the HttpModule function and can be used to encapsulate and modify Http requests, in fact, C/C ++ can be programmed and processed here, So C/C ++ can also be used as a website). After sf_policy_auth_complete is executed, the request will be processed by ISAPI Extension, after the processing is complete, it is returned to the ISAPI Filter to continue the subsequent steps. Figure 2 shows the architecture.
Figure 2
Note: In ASP. net isapi, the http request will be checked again for security information. At this point, the request will be checked twice, once in IIS, once in ASP. NET, which is also the reason why the Web service developed using Asp.net can use service-based verification..
Finally, ASP. net isapi loads CLR. Through AppManagerAppDomainFactory (located in System. web. the Create method of Hosting namespace) creates an Application Domain for the Application. Each Application Domain is independent of each other, so the website will not interfere with each other directly. Then process the Request through the ProcessRequest of ISAPIRuntime, and then enter the process to ASP. NET Http Runtime Pipeline (in fact, the process is very complicated, and there are many abstract classes and interfaces in the middle. Here we start from ApplicationHost and finally create the branch starting with ISAP, because the website is hosted in IIS)
Ii. ASP. NET internal
1. Create an application domain
ApplicationHost has a static CreateApplicationHost method.
HostType: indicates the communication object used for cross-origin access. It must be derived from MarshalByRefObject. The method defines the Assembly as hostType (generally in the bin directory of the website or GAC, of course we can also customize )., First, this method loads an ApplicationManager object (mainly some context information), and then calls the method in red box in the figure (the CreateAppDomainWithHostingEnvironment method is finally called) to create an application domain. In fact, you are reading system configuration information, such as the webconfig file trustLevel in the system environment, and then creating the corresponding application domain.
2. HttpRuntime processing requests
After the application domain is created, HttpRuntime processes the request using the PorcessRequest method. Let's look at the ProcessRequest method.
No.1: an instance of the HttpWorkerRequest class. It is an abstract class and plays a very important role in processing requests. It mainly obtains almost all the information of requests, and then wrap it in an object. It is rarely called externally. The figure shows some of its methods.
No. 2 internal Request Handling Method
Finally we can see the familiar HttpContext and IHttpHandler:
2.1 HttpContext
In HttpContext, we mainly construct two class instances: HttpRequst and HttpResponse objects. The rest is controlled by programmers.
2.2 HttpApplication
It can be seen from the code. An HttpApplicationFactory factory is used to manage HttpAplication instances. An object pool exists in the factory so that the created objects can be reused, however, each object processes only one request at a time.
There are many things to be processed in the request process. Asp.net introduces the pipeline mechanism to encapsulate these processing processes through events so that programmers can program them. For more information about pipelines, see the Introduction http://book.51cto.com/art/201102/245029.htm here
2.3 IHttpHandler
An external reference interface of HttpApplication can implement ProcessRequest () processing.
Http://www.cnblogs.com/stwyhm/archive/2006/08/09/471765.html
2.4 IHttpModule
It is actually an external programming interface for events in HttpApplication. You can customize implementation events, encapsulate or modify Http requests and Http responses.
We will not discuss how to use it here.
Recommended: http://www.cnblogs.com/stwyhm/archive/2006/08/09/471729.html
2.5 System. Web. UI. Page
The Page class finally implements the IHttpHandler interface and gets the request processing function. In addition, it also has its own ProcessRequest () implementation, including adding some multilingual information, finally, render the HTML page. I will not discuss it in detail here. (The Application in Page is familiar with the object of HttpApplicationState, not HttpApplication)