Asp. Net Request Processing Mechanism and asp.net Request Mechanism

Source: Internet
Author: User
Tags what is asp

Asp. Net Request Processing Mechanism and asp.net Request Mechanism

Original article: http://www.cnblogs.com/cilence/archive/2012/05/28/2520712.html

 

Asp. net Request Processing Mechanism preface we all know that the Web request response is based on the Http protocol, so we can understand that a Web request and response process, it is actually a process of sending an Http request and receiving an Http response. The client sends an Http request to the server. The server receives the request, generates a response packet, and sends the response packet back to the client. This completes a Web interaction between the client and the server. What is Asp. Net? I like Asp. net definition, such as Asp. net is an AOP framework that runs on the CLR managed code and processes Web requests and responds to Web requests. It is an engine used to process Web requests. It is not just a commonly used WebForm, WebService, IHttpHandler, but also a lot of process... from the browser to the server, let's take a look, when we enter in the browser address bar http://www.cnblogs.com Click the Enter key when accessing the blog site. At this time, a Request is generated from the browser and sent http://www.cnblgos.com When the request arrives at the web server, the HTTP. SYS component in the Windows Kernel of the web server will capture the request. When the HTTP. SYS component analyzes that this is an Http Request to be sent to the IIS server for processing, the HTTP. SYS component will send the Request to the IIS server for processing. The IIS server analyzes the context-type of the Request and then matches it from the handler ing table. When the context-type of the Request can be matched in the handler ing table, the IIS server then submits the request to the corresponding program in the ing table for processing. Figure 1: processing program ing table in IIS When IIS finds that there are no matching items in the processing program ing table (when there are no matching items, in general, it is a Request for "static files"), directly download the file in the corresponding path of the Request. Such as. jpg, HTML, and xml.css files. Figure 2: the process of arriving at the server from the browser is back. When the server is processing dynamic files such as aspx. ashx and so on, the IIS server sends the Request to the aspnet_isapi.dll file for processing. ISAPI is the first and most powerful Request packet original Web Request entry point. aspnet_isapi.dll is a very low-layer and unmanaged win32API. This dll is very simple and efficient, performance has also been optimized by Microsoft. It is used to process the underlying commands and function callback, and provides the application-level service functions and interfaces for high-level programs. When the aspnet_isapi.dll receives the Request, the aspnet_isapi.dll will be transferred to the Web server. net Framework, and finally load the CLR runtime environment, create an ISAPIRuntime object, and then call the ProcessRequest () method of the ISAPIRuntime object. ISAPIRuntme. the ProcessRequest () method is to enter ASP. net's first entry ISAPIRuntime. after the ProcessRequest () method is called, the original Request information of the Request is encapsulated into the HttpWorkRequest class. Because the Request packets encapsulated by the HttpWorkRequest class are very primitive and complex, so Microsoft did not publish it. Run the StartProcessing () method to create the HttpRuntime object and call its static method ProcessRequest (). Figure 3: How to start ASP. NetHttRuntime, HttpContext, and HttpApplication? After the HttpRuntime object calls its static method ProcessRequest (), our Web requests start slowly entering the application layer level, why? ProcessRequest () does a lot of work. You can use the Reflector tool to view details, but it is roughly divided into four parts: 1. create a new HttpContext instance for the request (this object is our common HttpContext context object), and encapsulate the most primitive request packets in HttpWorkRequest into the HttpRequest object of the HttpContext object. 2. Use HttpApplicationFactory to obtain a specific HttpApplication instance. 3. Call HttpApplication. Init () to create an event request pipeline. 4. The Init () method triggers the HttpApplication. ResumeProcessing () method to start executing the Asp. Net event request pipeline. Figure 4: The relationship between HttpRuntime, HttpApplication, and HttpContext Asp. Net event request pipeline describes Asp. Net as an Aop framework, while Asp. Net event request pipeline is a bit. Asp.. Net event request pipeline is a list of events that Microsoft provides to help programmers process Web requests. These events are executed in sequence, we can modify the Web request execution logic by registering or removing methods we write on these events. Figure 5: When the ASP. Net event request pipeline creates the requested Page Object and converts it to the IHttpHandler interface. Between the ninth event and the second event, the SessionId sent by the browser is received. First, the IHttpHandler interface will be converted to the IRequiresSessionState interface. If the conversion is successful, Asp. net searches for the corresponding Session object based on the SessionId in the Session pool of the server, and assigns the Session object to the Session attribute of the HttpContext object. If the API fails to convert to IRequiresSessionState, the Session is not loaded. Between 11th and 12th events, the ProcessRequest method of the page object created in the eighth event is called. When we directly use the *. ashx page, a FrameworkInitialize () is called directly, and a response packet is generated and sent back to the client. When we use the *. aspx Page, it inherits from the Page class, while the Page class implements the IHttpHandler interface. Because the Page class implements the IHttpHandler interface, the FrameworkInitialize () method is called in the ProcessRequest method. In the FrameworkInitialize () method, Asp is created. net page Control tree (Create html tree), in which the ProcessRequestMain method is called, and the entire Asp is executed in this method.. Net page lifecycle. IHttpModules requests are sent through the event pipeline. Some column events are triggered. We can see these events in the Global. asax Global configuration file. However, because this is an event assigned by the program, it may not be what we want. If we want to create an HttpApplication event pipeline that can be reused to process Web requests, we want to reuse the code or develop it into a plug-in form. Then we can use IHttpModules. IHttpModules is easy to configure. You only need to configure it in Web. config. The specific HttpModules only needs to implement the IHttpModules interface and register its own method. <? Xml version = "1.0"?> <Configuration> <system. web>

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.