ASP. net mvc processing pipeline

Source: Internet
Author: User

Original article: http://www.cnblogs.com/fzrain/p/3651693.html

The following describes the parts: routing module

1. The first stop in the ASP. net mvc processing pipeline is the routing module. When a request arrives at the routing module, the MVC Framework matches the current request according to the routing template configured in the Route Table to obtain the corresponding controller and action information. The specific matching process is implemented by using UrlRoutingModule (System. Web. Routing. UrlRoutingModule.

2. when ASP. when the net mvc application is started for the first time, the routing system will add the routing rules we registered (which requests are intercepted) to the Route Table. An application contains a Route Table in the Global. the Application_Start event in asax is created:

    { controller = , action = , id = 

3. when the UrlRoutingModule finds a matched routing rule in the Route Table, it will find the corresponding IRouteHandler (System. web. mvc. IRouteHandler) instance (default is System. web. mvcRouteHandler), obtain an IHttpHandler instance based on this RouteHandler (default: System. web. mvcHandler)

 

Controller Initialization

1. The ProcessRequest method in MvcHandler is the lifecycle of ASP. net mvc. This method uses the instance of IControllerFactory (default: System. Web. Mvc. DefaultControllerFactory) to create the corresponding controller:

   .ProcessRequestInit(httpContext,  controller, 

Action execution

1. After the controller is created, it will then execute its own InvokeAction () method:

   InvokeAction(ControllerContext controllerContext,  actionName)

2. after the appropriate action is selected, model binders (default: System. web. mvc. defaultModelBinder), which extracts data from http Request Parameters and implements type conversion and data validation (for example, whether required or not, data format, etc) and whether it is automatically assembled into the parameter System of the action method. web. mvc. defaultModelBinder

3. Authentication Filter is a new Filter in mvc5, which is executed before the authorization filter to authenticate users. Before MVC5, authentication and authorization were implemented through the authorization filter, But now these two operations are separated and managed separately.

4. Action filters has two methods: OnActionExecuting and OnActionExecuted, which are executed before and after the action is executed. We can also implement your personalized filtering mechanism through the IActionFilter interface.

5. The next step is to execute the code we usually write in the action method (based on the corresponding results of the request)

Execution of ActionResult

1. There will still be a filter (ResultFilter) before and after the ActionResult execution. Similarly, you can customize your own filter logic by implementing the IResultFilter interface.

2. ActionResult is to return the user request result processed by bal dal. Therefore, ViewResult, PartialViewResult, RedirectToRouteResult, RedirectResult, ContentResult, JsonResult, FileResult and EmptyResult are specific return types.

3. The above return types can be roughly divided into two categories: ViewResult and non-ViewResult. If you want to generate an html page and insert ViewResult to the client, other elements such as returned text and json data are classified into non-ViewResult. You can directly return non-ViewResult.

Initialization and rendering of View

1. For ViewResult, the appropriate View Engine calls the IView Render () method to Render the View:

 

2. The entire process is implemented by IViewEngine (System. Web. Mvc. IViewEngine. ASP. net mvc provides webform (. aspx) and Razor (. cshtml) template engine, you can implement your own ViewEngine by implementing the IViewEngine interface, and then register the following in the Application_Start method:

  ViewEngines.Engines.Add(

3. Finally, Html Helpers will help us generate input tags, AJAX-based forms, and so on. Html Helpers is an extension method of the HtmlHelper class, so it is very easy to extend it further.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.