I have been wondering how a request sent from a client connects to IIS on the server side, and how IIS reads the code I published, and return the files on the server. What is the processing process.
1: When you enter an address in your browser or click a link, you have sent an HTTP request (the site is located based on the host header, IP address, or port number of the request );
2: According to the HTTP protocol, when a request arrives at the corresponding host server, it is received by the system process HTTP. sys on the server (which can be understood as a process specially processing HTTP requests;
3: After HTTP. sys receives the request signal, it passes it to the worker process in the application pool, that is, the IIS process inetinfo.exe,Note: At this time, the server process andIISConnect.
Iisprogress can process general static pages such as. html. After processing, the HTML page is directly returned to the client for display;
4: If it is a page such as. aspx or cshtml, IIS cannot process it directly. In this case, the IIS process will load a page called aspnet_isapi.dll;
5: When the ISAPI receives the Processing request, it starts an ASP. net workflow and forwards the request information to the ASP. NET workflow (aspnet_wp.exe ),Note: At this timeIISAnd ASP. NETConnect.Next, the control is controlled by aspnet_wp.
[Let's first understand what appdomain is, feel this good http://allanpie.blog.163.com/blog/static/21320410200921311273632/, I understand appdomain is a can process ASPnet process (. DLL) environment or application domain, we know ASP. to run the. NET program.. NET Framework is a basic platform and can be run only after it is hosted by the CLR (Common Language Runtime Library. ASP. NET is a complex engine that uses hosted code to process Web requests from start to end.
Appdomain contains several important objects.
Isapiruntime: responsible for solving the necessary information of the HTTP request, which forwards the information and request to httpruntime.
Httpruntime: the main task is to create an httpcontext object for each customer who initiates a request. This stuff manages the httpsession object.
Each visitor has their own httpcontext object and httpsession object. You can find the corresponding class name in the. NET Framework library, such as system. Web. httpcontext, system. Web.
Httpsessionstate and so on. These two objects are part of the appdomain runtime environment. These two classes are called system. Web. Hosting. isapiruntime, and system. Web. httpruntime .]
6: If the control is left to the aspnet_wp process. in the. NET environment, the appdomain will be created first to execute the application domain. When the appdomain is created, the isapiruntime and httpruntime classes will be instantiated as part of the appdomain.
7: After the appdomain Initialization is complete, you need to establish a session to pass the request to one of the classes httpruntime. The relationship between the classes is: httpruntime is responsible for creating httpcontext and httpsession,
Httpcontext is responsible for managing httpsessions.
From the time when an HTTP request is submitted to this (httpcontext is created after httpruntime), the application we released on the server is still not running, or, the requester's request is not actually processed, and the previous work is both preparation or auxiliary work.
8: Next, in addition to creating httpcontext and httpsession, httpruntime also creates an important object httpapplication.
Httpapplication calls the processrequest method to process user requests. Specifically, it creates an httpcontext instance,
9: httpruntime searches for or creates an object for a Web application that can process the request using context information. Httpapplication factory is responsible for returning the httpapplication instance. The httpapplication object uses an ihttphandlerfactory-type instance to return httphandler (HTTP handler) to the httpruntime object. A page is just an HTTP handler object.
Finally, the httpruntime object calls the processrequest method of the ihttphandler Page Object. Httphandler processes the request according to the extension of the user request file, and sends the request result, that is, HTML, to the customer's browser.
In the MVC source code, the mvchandler class inherits the ihttphandler interface and implements the processrequest (httpcontext) method, which is the entry for MVC program running.
10: At this time, I would like to know how the routing in MVC is linked with httpapplication. How does the urlroutingmodule intercept the pipeline event of httpapplicatioin and introduce HTTP request into the MVC framework.
In urlroutingmodule. in the CS file, we can see that when the urlroutingmodule initializes and calls the init method, it registers the httpapplication's postresolverequestcache pipeline event. Therefore, when the httpaplication object (mvcapplication) is executed, a postresolverequestcache event is triggered, so as to direct httprequest to the MVC Module
The first part involved in ASP. net mvc is urlroutingmodule, which is part of system. Web. routing. Urlroutingmodule is used to check whether the requested URL matches the file on the local disk for the first time. If the request matches, urlroutingmodule sends the request directly back to IIS. IIS processes the request based on the address. If the urlroutingmodule does not find a matching file on the disk. It checks the routecollection structure to determine whether to continue the transfer. urlroutingmodule introduces routehandler and the matched path entry (mvcroutehandler by default ). Then, appropriate httphandler will be introduced to process and request-related logic. By default, the httphandler will be mvchandler.
11: How is the URL routing component combined with the ASP. net mvc framework.
When the MVC program is started for the first time, register the routing registerroutes (routetable. routes) in the application_start function; in routes. maproute (...) Function, register the custom routing rules to the system. Web. Routing component, route = new route (URL, new mvcroutehandler ())
Note: When processing this requestHttpapplicationClass to execute the following events. Want to expandHttpapplicationClass developers need to pay special attention to these events.
When a request is verified, the browser checks the information sent and determines whether it contains a potentially malicious flag. For more information, see validaterequest and script intrusion overview.
If you have configured any URL in the urlmappingssection of the web. config file, perform URL ing.
The beginrequest event is triggered.
The authenticaterequest event is triggered.
This triggers the postauthenticaterequest event.
The authorizerequest event is triggered.
This triggers the postauthorizerequest event.
This triggers a resolverequestcache event.
The postresolverequestcache event is triggered.
Based on the file extension of the requested resource (ing in the application configuration file), select an ihttphandler class to process the request. If the request is for an object (PAGE) derived from the page class and needs to compile the page, ASP. NET will compile the page before creating an instance.
The postmaprequesthandler event is triggered.
The acquirerequeststate event is triggered.
This triggers the postacquirerequeststate event.
Raises the prerequesthandlerexecute event.
Call the appropriateIhttphandlerClass processrequest method (or asynchronous beginprocessrequest ). For example, if the request is for a page, the current page instance processes the request.
The postrequesthandlerexecute event is triggered.
This triggers the releaserequeststate event.
The postreleaserequeststate event is triggered.
If the filter attribute is defined, the response is filtered.
The updaterequestcache event is triggered.
This triggers the postupdaterequestcache event.
An endrequest event is triggered.
When we send a request to the Asp.net MVC website, five main steps are taken:
Step 1: Create a routetable when the Asp.net application is started for the first time. Routetable maps URLs to handler.
Step 2: urlroutingmodule intercepts the request. Step 2 occurs when we initiate the request. The urlroutingmodule intercepts every request and creates and executes a suitable handler.
Step 3: Execute mvchandler to create a controller, pass the controller into controllercontext, and then execute the controller.
Step 4: Execute the Controller controller to detect the Controller method to be executed, build the parameter list and execute the method.
Step 5: Call the renderview method. In most cases, the Controller method calls renderview () to present the content back to the browser. The Controller. renderview () method delegates this job to a viewengine.
These knowledge and images are summarized in the following blog to facilitate viewing.
Refer:
Http://blog.csdn.net/jilate/article/details/437506
Http://www.cnblogs.com/tmfc/archive/2006/08/29/489779.html
Http://blog.csdn.net/virone/article/details/4531800
Http://msdn.microsoft.com/zh-cn/library/ms178473%28v=VS.80%29.aspx
Http://blog.csdn.net/wx845204140/article/details/7194743