1. Overview of ASP. NET operating principles
For example, after an HTTP request is sent and received by the IIS server, IIS first loads the corresponding DLL file for the requested page type, then, the request is sent to the module that can process the request. in net, this module is called httphandler. Why can aspx files be processed by the server? That is because the default httphandler on the server is used to process aspx files, before IIS sends this request to a module that can process this request, it also needs to go through some httpmodules, which are default modules of the system, in addition, different httpmoduls must be processed before the HTTP request is sent to httphandler. This is like if we want to fly an international flight to a foreign country, before you actually get on the plane, the airport construction fee should be purchased, the identity should be verified through registration procedures, the luggage should be packed and checked, and the security inspection should be conducted. Now, the temperature and other inspections should be carried out, and a series of strict procedures should be adopted. What are the advantages of doing so? One is for some necessary processes, the other is for security, the third is to improve efficiency, and the fourth is for us to be able to control more links, that is, our control capability is enhanced. The above are all systems. How can we say that we can control HTTP requests? Can we establish our own httpmodule and httphandler? The answer is yes. But we should not rush to do things first. Let's take a deeper look at the operating mechanism.
2. ASP. NET operating mechanism
the preceding figure shows how an HTTP request is processed by the server, at the same time, we can see from this figure that the request is in charge of all client input. The figure shows four possible routes for an HTTP request.
(1) When you access this page for the first time, the request first goes through the processing of httpmoduls and httphandler, while in the processing of httphandler, the server redirects you to the page you actually want to access, finds the class behind the page through the aspx engine, and instantiates it as a temporary object , in this process, a series of events are triggered. Some of the events need to be processed by the method in the object. Then, the server will send the processed page to the response object, then, the response object sends the page (in fact, the HTML page) to the client. This is the first route.
(2) When you resubmit some information on this page and send a request to the server, because the sessions between your servers have been established and the temporary object you are in has been created on the server, you do not need to initialize the page any more, therefore, the second route follows httpmoduls and httphandler, then interacts directly with the temporary object, and finally sends the page back to the client.
(3) the third line is different from the second line. when processing a request, if ASP cache needs to be called, the temporary object will directly extract information from the ASP cache and return it;
(4) When you refresh the page, the server receives the request and finds that the request has been processed previously, the processing results are stored in the output cache managed by a default httpmodule. Then, we can extract information from the cache and return the results without re-processing them.