. Net Mvc framework principle,. netmvc framework
. Net Mvc framework principle
This article briefly describes the principles and summarizes them.
1. When an Http request is sent, it will be intercepted by the URLRoutingModule (this is to officially enter the MPs queue, and the following chapter will talk about MPs queue events)
2. Based on the IsapiWorkerRequest object, HttpRuntime will create a Context equivalent to the Http request: HttpContext
3. encapsulate HttpContext and change it to the HttpContextWarpper object. Then, locate the RouteData object that meets the current request URL from the Route set, and encapsulate the HttpContext and RouteData objects into RequestContext objects.
4. Obtain IHttpHandler Based on RouteHandler in the RouteData object. MvcHandler is an implementation class of IHttpHandler.
5. Execute IHttpHandler, execute a specific Controller through reflection, and execute a specific Action
UrlRoutingMudule and MVCHandler
UrlRoutingMudule inherits IHttpMudule, MVCHandler inherits IHttpHandler, HttpMudule and HttpHandler are both objects in HttpApplication, and HttpMudule is the objects loaded and initialized according to the configuration file during HttpApplication initialization, it is mainly responsible for injecting the required operations into the processing process of the entire HTTP request by registering the corresponding events of HttpApplication. Many functions of ASP. NET, such as identity authentication, authorization, and caching, are implemented through the corresponding HttpModule. The final implementation of HTTP request processing is another important object: HttpHandler. Different resource types have different HttpHandler types. For example, the HttpHandler corresponding to the. aspx Page is System. Web. UI. Page, and the HttpHandler corresponding to the. svc file of WCF is System. ServiceModel. Activation. HttpHandler.
This article focuses on learning from the MVC series-MVC source code: Creating Your Own MVC Framework (great explanation)