Detailed explanations of Asp.net httphand and httpmodule, including ASP. NET's process for HTTP requests.

Source: Internet
Author: User

Measure the test taker's knowledge about the background Web Server action flow when a user requests a. ASPX page. After learning about this process, we will understand the functions of httphandler and httpmodule.

First, let's take a look at the IIS system. It is a program that manages website content and responds to customer requests (HTTP requests. When a user requests a page, IIS responds as follows (ignoring permissions ):
1. Convert the virtual path requested by the other party to the physical path
2. Search for the requested file based on the physical path
3. Find the file and obtain the file content.
4. Generate HTTP header information.
PS: For the HTTP header information (metadata) generated by IIS and IE, you can use this tool: http://www.blunck.info/iehttpheaders.html, which is a plug-in of IE and focuses on header information.
5. Send all the file content to the client: first the header information, then the HTML content, and finally the content of other files.
6. After obtaining information from the client IE browser, parse the file content and find the referenced files, such as. js. CSS. GIF, and request these files from IIS.
7. After IIS obtains the request, it sends the file content.
8. After the browser obtains all the content, it generates the content interface, and the customer will see the image, text, and other content.

However, iisis short-lived, that is, it only supports the content of Static HTML pages. In other words, it can only analyze file content such as .htm,.html. For pages with dynamic content that contain server-side operation code, such. ASP ,. aspx ,. CGI ,. PHP, etc. If IIS does not recognize these special tags, it will treat them as text and send them to the client without any processing.

To solve this problem. IIS introduces a mechanism called the Open extension of ISAPI. This is a standard component (COM Component). It is a filter + jump program. If special extensions are installed, when accessing files that cannot be processed by IIS, such. ASP and. in the aspx file, IIS starts this extension in its own process. As mentioned earlier, ISAPI is a filter first. When registering with IIS, it registers the file extensions that can be processed by each extension to IIS. After the extension is started, it processes the files that cannot be processed by IIS according to the defined method, and then redirects the control to the process that specifically processes the code. Let this process start to process the code, generate standard HTML code, add the code to the original HTML, and finally return the complete HTML to IIS, IIS then sends the content to the client.

I will take a description of the steps for requesting the Asp.net page:
1. The client IE browser sends a request to a Web server through the HTTP protocol, as shown in figure
Http://www.microsoft.com/china/msdn/default.mspx

2. When a request arrives, IIS checks the resource type (that is, the extension of the request file, and finds that it cannot be processed by itself) and calls ASP. net isapi extension. If the default process model is enabled, aspnet_isapi queues requests and assigns them to the secondary process. All request data is sent through asynchronous I/O. If the IIS 6 process model is enabled, requests are automatically queued in the secondary process (w3wp.exe), which is used to process the IIS application pool to which the application belongs. The IIS 6 auxiliary process does not understand ASP. NET and the managed code in any situation. It only processes *. aspx extensions and loads the aspnet_isapi module. When ASP. net isapi is run in the IIS 6 process model, it works in different ways. It only loads CLR in the context of the w3wp.exe auxiliary process.

3. After receiving the request, the ASP. NET auxiliary process will notify ASP. net isapi that it will serve the request. Notifications are implemented through synchronous I/O. The synchronous model is used because the secondary process can process a request only when it is marked as "executing" in the ISAPI internal request table. If a request has been processed by a special auxiliary process, it cannot be specified to another process unless the original process has been canceled.

4. The response is sent to the aspnet_isapi that opens the asynchronous pipeline. Now, the Request status changes to "done" and will be deleted from the request table. If the secondary process crashes, all the requests being processed will remain in the "executing" status for a period of time. If aspnet_isapi detects that the secondary process has been canceled, it will automatically terminate the request and release all related IIS resources.

5. After the ISAPI obtains the response (the HTML content processed by the Asp.net Runtime Library), it returns the response to IIS and IIS will continue to process its content, parse the required files and send all the data to the client. Close the connection.

From the above description, we can know that the final step is the process of Asp.net processing, that is, what happened after the ISAPI of Asp.net starts the processing process.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.