[Add to favorites] Introduction to the underlying Working Mechanism of ASP. NET

Source: Internet
Author: User
Tags what is asp
About Underlying Working Mechanism of ASP. NET Recently, the discussion in the garden is very hot. I believe many people have read a classic article by Mr. Rick Strahl: a low-level look at the ASP. NET architecture. With Rick Strahl's consent, I will share his article Article I hope to help anyone who wants to know more about ASP. NET's working mechanism.

Note: The purpose of this article is only to provide some help to ASP. NET fans. Due to my limited ability, please criticize and correct this article. If you need to reprint the document, please keep the link for this article and the original English. Thank you!


1. What is ASP. NET?

2. From the browser to ASP. NET

3. ISAPI connection

4. Differences between iis5 and IIS6

5. Enter. Net Runtime

6. Loading. Net-a little mysterious

7. Return to runtime

8. httpruntime, httpcontext, and httpapplication

9. WebProgramHttpapplication

10. pass through the ASP. NET Pipeline

11. httpcontext, httpmodules and httphandlers

12. httpmodules

13. httphandlers

14. Have you provided sufficient underlying knowledge?

Abstract: ASP. NET is a powerful platform for building web programs. It provides great flexibility and capabilities to build arbitrary web programs. Many people only. net high-level frameworks, such as webforms and WebServices, are familiar. Therefore, in this article, I will elaborate on ASP. net, and explains how to hand over requests from the Web server to ASP. net runtime, and then through ASP.. Net HTTP pipeline to process these requests.

For me, understanding the internal working mechanism of a platform will always make me feel satisfied and comforted. Just like insights, it can help me write better programs. Knowing what the tools are for and how they are assembled into a part of a complex framework will make it easy for you to find a solution to the problem and when you modify and debug errors, are very important. The purpose of this article is to understand ASP. net at the underlying layer and how requests flow into the ASP. NET processing pipeline. At the same time, you will understand the core of the ASP. net engine and how a Web Request ends here. Many of the Knowledge mentioned here is unnecessary in your daily work. However, if you understand how ASP. NET routes requests to applicationsCode(Usually high-level), which will be very useful to you.

Note: The entire ASP. NET engine is fully built in managed code, and all of its scalability is built through managed code.

Most of ASP. NET users are familiar with webforms and WebServices. These high-level implementations make it easy to build web programs. ASP. NET is designed as a driver engine. It provides underlying interfaces to Web server and provides routing services for front-end and end of high-level Web applications. Webforms and WebServices are built on the ASP. NET Framework and are the most common methods for HTTP processing.

In fact, at a lower level, ASP. NET also provides enough flexibility. The HTTP runtime and request pipeline provide the same capabilities to build implementations similar to webforms and WebServices. Of course, these are already implemented using. Net hosted code. If you need to build a custom HTTP processing platform, which is a little lower than webforms, then you will use all these similar functions.

Webforms is undoubtedly the easiest way to build most web interfaces. However, if you want to customize a content processor or perform special processing on inbound and outbound content, or you need to customize an application server interface for an application, so using these low-level processing or modules will get better performance, in addition, you can gain more control in real request processing. Although high-level implementations such as webforms and WebServices provide similar functions, they add too much control over requests (resulting in performance degradation ). Therefore, you can create a different environment to process these requests at a lower level.

What is ASP. NET?

Let's start with the simplest definition. What is ASP. NET? I usually like to use the following statement to describe ASP. NET.

ASP. NET is a mature engine platform that fully uses hosted code to process Web requests. It is not just webforms and WebServices.

ASP. NET is a request processing engine. It obtains the client request and transmits the request to an end point through its built-in pipeline. At this end point, developers can add the logic code to process the request. In fact, this engine is completely separated from HTTP or web server. In fact, HTTP is a component during runtime. You can host it on an application outside of IIS. It can even be combined with other services. For example, you can host HTTP runtime in a Windows desktop application (for details, see: http://www.west-wind.com/presentations/aspnetruntime/aspnetruntime.aspx ).

By using the built-in pipeline to route requests, HTTP runtime provides a complex but elegant mechanism. Many objects are involved in each layer of request processing, but most objects can be extended through Derivation or event interfaces. Therefore, this framework is highly scalable. Through this mechanism, it is possible to enter lower-level interfaces such as cache, identity authentication, and authorization. You can filter the content before or after processing the request, or simply route the client request that matches the specified signature to your code or to another URL. For the same thing, you can use different processing methods, and the implementation code is very intuitive. In addition, HTTP runtime also provides the best flexibility between ease of development and performance.

The entire ASP. NET engine is fully built in managed code, and all the scalability functions are provided through the extension of managed code. For a powerful. NET Framework, using your own things to build a mature, high-performance engine architecture has become a testament. However, Asp. net is most impressed by the ambitious design, which makes the work above it very easy and provides the ability to hook almost any part of request processing.

ASP. NET can be used to complete some tasks. Previously, these tasks were completed using ISAPI extension and filtering on IIS. Despite some restrictions, Asp has made great progress. ISAPI is an underlying Win32 API, with only one MB of its interface, which is very difficult for large-scale program development. Because ISAPI is the underlying interface, its speed is also very fast. However, enterprise-level program development is quite difficult to manage. Therefore, ISAPI serves as a bridge interface for other applications or platforms within a certain period of time. However, ISAPI is not discarded in any case. In fact, ASP. NET and IIS interfaces on Microsoft platform communicate with each other through the ISAPI extension of the host in. net, and then directly access ASP. NET runtime. ISAPI provides core interfaces for communication with Web servers. ASP. NET then uses unmanaged code to obtain requests and send responses to client requests. The content provided by ISAPI is similar to httprequest and httpresponse through public objects. It exposes unmanaged data by hosting objects through a well-designed and accessible interface.

From the browser to ASP. NET, we start from the starting point of the lifecycle of a typical ASP. NET Web request. You can enter a URL in your browser, click a hyperlink, and submit an HTML form (a POST request), or call a client program based on ASP. net WebService (through ASP.. net ). On the server side, iis5 or IIS6 will receive this request. The bottom layer of ASP. NET communicates with IIS through ISAPI extension. Then, through ASP. NET, this request is usually routed to a page with the. aspx extension. However, how the processing process works depends entirely on the execution of the HTTP processor (handler. This processor will be installed to process specified extensions. In IIS,. aspx is mapped to the ASP. net isapi dll file aspnet_isapi.dll through "application extension. Each request that triggers ASP. NET must be identified by a registered extension pointing to aspnet_isapi.dll.

Note: ISAPI is the first IIS entry point in custom web request processing with the highest performance.

Depending on the extension, ASP. NET routes a request to an appropriate processor, which is responsible for processing the request. For example, the extension of WebServices. asmx does not route a request to a page on the disk, but routes the request to a class with the specified feature added to the definition (webmethodattribute, this feature identifies it as an implementation of Web Services. Many other processors will be installed along with ASP. NET. Of course, you can also define your own processor. All httphandler in IIS is mapped and points to ASP. net isapi extensions. These httphandler are also configured in Web. config to route requests to the specified HTTP processor for execution. Each processor is A. Net class used to process specified extensions. These processors can process Hello world with only a few lines of code, pages like ASP. NET, and WebService execution. At present, we only need to understand that extension is a basic ing mechanism, Asp. net can get a request from the ISAPI, and then route the request to the processor specified to process the request.

Related Article

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.