Detailed explanation of ASP.NET HTTPHAND and HTTPMODULE, including ASP.NET's processing flow for HTTP requests.

xiaoxiao2021-03-06  182

Understand the action flow of the WEB server of the background when the user requests a request for a .aspx page. When you understand this process, we will understand the role of httphandler and httpmodule.

First, let's take a look at the IIS system. It is a program that is responsible for managing the content of the website, and reacting the customer's request (already HTTP request). When the user makes a request for a page, IIS does the following reaction (ignore permissions): 1. Convert the virtual path of the other party to the physical path 2. Search the requested file according to the physical path 3. After finding the file, get the content 4 Generate HTTP header information. PS: About the HTTP header information (metadata) generated by IIS and IE, you can use this tool: http://www.blunch.info/iehttpheaders.html, it is a plugin for IE, specifically viewing header information. 5. Send all file content to the client: first is header information, then HTML content, and finally the content of other files. 6. After the client IE browser gets information, resolve the contents of the file, find out the reference file, such as .js .css .gif, etc., requests these files to IIS. 7. After obtaining the request, send the file content. 8. When the browser gets all content, generate the content interface, the customer will see the image / text / other content.

But IIS has a shortcoming, that is, it only supports the content of the static HTML page, that is, he can only analyze the contents such as .htm, .html. Like some dynamic content, the page type of server-side operation code, such as .asp, .aspx, .cgi, .PHP, etc., IIS don't know these dedicated tags, it will treat it as text, do not do Processing is sent to the client.

To solve this problem. IIS launched a mechanism called ISAPI's open extension, this thing is a standard component (COM component), he is a filter jump program, if a special extension is installed, then files that cannot be processed in IIS When such as .asp and .aspx files, IIS will launch this extension in their own process. Just said, isapi first a filter. When he is registered to IIS, you will register each extended file extension to IIS. After the extension is started, the files that IIS cannot process are processed according to the defined way, and then the control is jumped to the process of dedicated code. Let this process start processing code, generate standard HTML code, add these code into the original HTML, finally returns the complete HTML to IIS, IIS, send content to the client.

I will take a request for the request ASP.NET page Description: 1 Client IE Browser makes requests to a web server via HTTP protocol, such as http://www.microsoft.com/china/msdn/default.mspx

2 When the request arrives, IIS checks the resource type (that is, the extension of the request file is checked, and finding it is not what you can handle), call the ASP.NET ISAPI extension. If the default process model is enabled, the ASPNET_ISAPI will queue the request and assign the request to the auxiliary process. All request data is sent through asynchronous I / O. If the IIS 6 process model is enabled, the request will automatically queue in the auxiliary process (W3WP.exe), which is used to process the IIS application pool to which the application belongs. IIS 6 auxiliary process does not understand any situation of ASP.NET and hosting code, it is just processing * .aspx extensions and loads the ASPNET_ISAPI module. When ASP.NET ISAPI is running in the IIS 6 process model, its work mode is different, and the CLR is loaded only in the context of the w3wp.exe assist process. 3 After receiving the request, the ASP.NET assist process will notify ASP.NET ISAPI, which will serve the request. Notification is implemented by synchronous I / O. The reason why the synchronization model is used because the request is only marked as "executing" in the ISAPI internal request table, and the auxiliary process can start processing it. If the request has been processed by a special auxiliary process, it cannot be assigned to other processes unless the original process has been canceled.

4 After the completion, the response is sent to the ASPNET_ISAPI that opens the asynchronous pipe. Now, the requested status becomes "DONE", which will then be deleted from the request table. If the auxiliary process crashes, all requests that are being processed will remain "executing" status and lasts for a while. If the ASPNET_ISAPI detects that the secondary process has been canceled, it will automatically terminate the request and release all relevant IIS resources.

5 Finally, ISAPI gets a response (that is, after the HTML content processed by the ASP.NET Runture Base), returning the response to IIS, IIS will continue to process its content, resolve the required related files, and send all the data Give the client. Then close the connection.

From the above description, the final step is the process of ASP.NET processing, which is what happened after ASP.NET's ISAPI startup process.

转载请注明原文地址:https://www.9cbs.com/read-128323.html

New Post(0)