A brief description of the request response process for ASP.Net

  • 2020-05-16 06:47:34
  • OfStack

1. Simple process of browser request page

When a browser requests a static page, it sends a request to the server software, which goes directly to the corresponding static page and returns it to the browser.

When a browser requests a dynamic page, the server software receives the request, can't deal with it found. aspx file, according to the extension of the mapping table is going to find a corresponding handler (aspnet_isapi. dll), the handler implements server software interface provided, namely the server software via the interface calls to the method of the handler. aspnet_isapi.dll forwards the request to.Net Framework, which processes the dynamic page, creates the page object, generates the corresponding message, and responds to the browser.

When the server receives the dynamic page request from the browser, it goes to the assembly of the website to find the corresponding class, creates the object of the class by reflection, runs the ProcessRequest method to deal with the user's demand, and finally outputs the response data through the Write method.

When Write is executed, the data is put into the cache and the page is returned to the browser one time after execution.

2. 1 IHttpHandler interface for general handlers

When the server receives the request to create the page object, it finds that each file is a class, and it does not know how to call the method to create the page. Therefore, it needs an intermediate processing -- converting the object of the page class into an interface IHttpHandler type, and then implementing the processing by calling the methods in the interface.

A generic handler is a class that implements the IHttpHandler special interface. Any class that implements the IHttpHandler special interface can be used as the target program for an external request.

If the requested class does not implement the interface, an error occurs during the conversion, indicating that the IHttpHandler interface is not implemented. So, the method in the 1 general handler actually implements the method in IHttpHandler.

3.1 general handling of program details

IHttpHandler is an important interface. context encapsulates all the request messages from the browser. The ProcessRequest method means that the code in this method is called when the page is accessed. Context.Response is the encapsulation of the output, and ContextType is the ContextType value in the response message, which is the way to respond to the output.

IsReusable is another method in IHttpHandler that sets whether the page can be reused to reduce the stress on the Web server on multiple visits.

4. Detailed request process

The server receives the user request, aspnet_isapi.dll hands the request over to Application Domain, which indirectly calls HttpRuntime's static method to process the user's request.

First, the request message is analyzed and encapsulated into HttpWorkerRequest object. Then, the request message is unpacked and each field is encapsulated into a bit HttpRequest object (this object contains QueryString and Form methods).

HttpRequest object, HttpResponse object and so on, together constitute HttpContext object.

The HttpApplicationFactory class looks for available HttpApplication objects in the Application pool, if so, use them directly, and if not, create one. There is an ProcessRequest method in the HttpApplication object, and this method has an HttpContext object. It's just the thing for you.

The HttpApplication object enters the request pipeline and executes 19 delegate events, creating the object of the requested page at the 8th event, and executing the ProcessRequest method of the created object between the 11th and 12th events.

5. The page life cycle of WebForm

After the 11th event of the request pipeline executes the PeocessRequest method of the created page class, the BuildControlsTree method is called to enter the page's life cycle.

In the page life cycle, a series of events will be called continuously, among which an Render method will traverse the entire control tree, generate the corresponding HTML code, and finally combine the HTML code of the entire page to return to the browser.


Related articles: