1..net mvc principle overview, 1 .. netmvc Overview
The request is received by the iis server based on the ip address and port. If the request is a static file, the file content is directly returned. If the request cannot be parsed, the corresponding request suffix is found based on the ing rule.
The ASPNET_ISAPI.dll processing assembly for processing.
1. IsapRuntime is generated, and the WorkRequest object is created,
2. Next, instantiate HttpRunTime and generate the HttpContext context object. At this time, the built-in objects such as Request, Response, Session, and Application are initialized,
3. Then the HttpApplicationFactory factory object is created. During the first access, it calls the Application_Start method in the Global File,
Generate an HttpApplication object, read the system configuration file, including our route configuration and constraints, create an HttpModel object, call the Init method, and register these methods into the pipeline,
4. ProcessRequest is called by the HttpApplication object, which executes the pipeline time.
4.1 The first event is the BeginRequest method, and then the key point is to create the MVCHandler object at 7th times,
4.1.1 store HttpContext in it, read the routing rules in the route table to generate RouteData objects, and store them together with HttpContext to create RequestContext, and then pass the RequestContext object to RoudlerHandler. getHttpHandler obtains MVCHandler and calls context. remapHandler saves mvchandler to httpcontext
4.2 8th Events Check whether RemapHandler in HttpContext is empty. If not empty, skip this event, which is also one of the most important differences with aspx, in aspx, we want to create a Page Control tree. however. net mvc is skipped here
Between 4.3 and 11th events, a controller object is created based on the Controller name obtained from the Controller factory, And the RequestContext is passed in to call the ControllerBase Execute method of the controller parent class, set RequestContext to ControllerContext and execute the ExecuteCore method. Find and call the corresponding Action method based on the request method name, that is, the business we write, and return the View, actionResult is called. execute method, that is, ViewResultBase of the parent class. executeResult: Find the corresponding View engine, get the View object of ViewEngineResult, get the TextWriter object and ViewContext object of Response to call the Render method of the engine, generate html code, and writer it out.