IIS processing page Running Mechanism:
IIS itself cannot process pages like the aspx extension. It can only directly request static files like HTML. The reason why IIS can process pages with the extension aspx is that IIS has an ISAPI (Internet server application programe interface, Internet server applicationProgramInterface) Filter, which is a COM component,Although this ISAPI sounds very elegant, it is also an "application", but you can take a closer look at its full name to understand that it is actually only an interface and acts as a proxy,It maps the requested page (File) and the actual processing program corresponding to the suffix.. When the ASP. NET service is registered with IIS, it will add a Win32 dynamic extension library aspnet_isapi.dll. And register the page extension (such as aspx) that can be processed by the extension to IIS. After the extension is started, it processes pages that cannot be processed by IIS according to the defined method.
When the client requests a server resource, the HTTP request will be intercepted by the inetinfo.exe process (WWW Service), then check the type of the requested resource, and based on the resource ing information (stored in the IIS metadatabase, a configuration database dedicated to IIS) allocate the requested resources to a specific handler module. If the requested static resources (IMG, text, HTML, etc.) are processed by IIS (IIS accesses the requested file on the Local Web Server), and the content is output to the console, the browser that sends the request can receive it. Requests to be processed on the server will be uploaded to the registered extension module, And the aspx request will be allocated to aspnet_isapi.dll to start processing.CodeGenerate standard HTML code, add the HTML to the original HTML, and finally return the complete HTML to IIS. IIS then sends the content to the client's browser.
ASP. NET Framework processing of requests:
As mentioned above, IIS assigns pages like aspx to aspnet_isapi.dll, and then processes them as follows:
1. aspnet_isapi.dll uses an HTTP listener (IIS Worker Process, w3wq.exe in iis6.0, and aspnet_wp.exe in iis5.0). Then the Asp.net Framework processes the HTTP request through httpruntime.
2. httpruntime first determines the class name for processing the request. httpruntime calls the class to obtain the instance of the requested class through the public interface ihttphandler.
3. Call httpruntime. processrequest starts to process the page to be sent to the browser. Specifically, it creates an httpcontext instance which encapsulates all http-specific information related to the request and initializes a write object to cache the markup code.
4. httpruntime searches for or creates an object for a Web application that can process the request using context information. Httpapplication factory is responsible for returning the httpapplication instance.
5. The httpapplication instance reads data from the machine. config, Web. all httpmodule components configured in config. These components register themselves in some events and insert themselves into ASP.. NET Request Processing pipeline. When these events occur, ASP. NET calls the HTTP module that is interested in the request, so that the module can process the request.
5. The httpapplication object uses an ihttphandlerfactory-type instance to return httphandler (HTTP handler) to the httpruntime object. A page is just an HTTP handler object. Httphandler processes the request information and sends responses. The httphandler function must implement the ihttphandler interface.
6. Finally, the httpruntime object calls the processrequest method of the ihttphandler Page Object.
ASP. the net request processing process is based on the pipeline model, which consists of multiple httpmodules and httphandler, Asp.. Net passes the HTTP request to each httpmodule in the pipeline in sequence, and is finally processed by httphandler. After the processing is completed, it passes through the HTTP module in the pipeline again and returns the result to the client. We can intervene in the request processing process in each httpmodule.
Note: During HTTP request processing, only one httphandler can be called, but multiple httpmodules can be called.
When the request arrives at httpmodule, the system has not actually processed the request, but we can add some other information before the request is passed to the processing center (httphandler, or intercept the request and do some additional work, or terminate the request. After httphandler finishes processing the request, we can re-process the request processing result in the corresponding httpmodule and return it to the client.