https://docs.microsoft.com/en-us/aspnet/mvc/overview/older-versions-1/overview/understanding-the-asp-net-mvc-execution-process

Requests to an ASP.NET MVC-based Web application first pass through the UrlRoutingModule object, which is an HTTP module.

This module parses the request and performs route selection.

The UrlRoutingModule object selects the first route object that matches the current request. (A route object is a class that implements RouteBase, and is typically an instance of the Route class.)

If no routes match, the UrlRoutingModule object does nothing and lets the request fall back to the regular ASP.NET or IIS request processing.

UrlRoutingModule选择第一个匹配的route object

From the selected Route object, the UrlRoutingModule object obtains the IRouteHandler object that is associated with the Route object.

Typically, in an MVC application, this will be an instance of MvcRouteHandler. The IRouteHandler instance creates an IHttpHandler object and passes it the IHttpContext object.

By default, the IHttpHandler instance for MVC is the MvcHandler object. The MvcHandler object then selects the controller that will ultimately handle the request.

UrlRoutingModule会从选择的route object中获取和route object相关的route handler,一般来讲是MvcRouteHandler

Route Handler会创建一个HttpHandler,并且传递HttpContext给HttpHandler,一般来讲是MvcHandler。MvcHandler负责选择Controller

Note

When an ASP.NET MVC Web application runs in IIS 7.0, no file name extension is required for MVC projects. However, in IIS 6.0, the handler requires that you map the .mvc file name extension to the ASP.NET ISAPI DLL.

The module and handler are the entry points to the ASP.NET MVC framework. They perform the following actions:

  • Select the appropriate controller in an MVC Web application.
  • Obtain a specific controller instance.
  • Call the controller's Execute method.

The following lists the stages of execution for an MVC Web project:

  • Receive first request for the application

    • In the Global.asax file, Route objects are added to the RouteTable object.
  • Perform routing

    • The UrlRoutingModule module uses the first matching Route object in the RouteTable collection to create the RouteData object, which it then uses to create a RequestContext (IHttpContext) object.
  • Create MVC request handler

    • The MvcRouteHandler object creates an instance of the MvcHandler class and passes it the RequestContext instance.
  • Create controller

    • The MvcHandler object uses the RequestContext instance to identify the IControllerFactory object (typically an instance of the DefaultControllerFactory class) to create the controller instance with.
  • Execute controller - The MvcHandler instance calls the controller s Execute method. |

  • Invoke action

    • Most controllers inherit from the Controller base class. For controllers that do so, the ControllerActionInvoker object that is associated with the controller determines which action method of the controller class to call, and then calls that method.
  • Execute result

    • A typical action method might receive user input, prepare the appropriate response data, and then execute the result by returning a result type. The built-in result types that can be executed include the following: ViewResult (which renders a view and is the most-often used result type), RedirectToRouteResult, RedirectResult, ContentResult, JsonResult, and EmptyResult.

Understanding the ASP.NET MVC Execution Process的更多相关文章

  1. [引]ASP.NET MVC 4 Content Map

    本文转自:http://msdn.microsoft.com/en-us/library/gg416514(v=vs.108).aspx The Model-View-Controller (MVC) ...

  2. Understanding ASP.NET MVC Filters and Attributes

    这篇文章把Asp.net MVC的filter介绍的很详细,值得收藏. http://www.dotnet-tricks.com/Tutorial/mvc/b11a280114-Understandi ...

  3. 【ASP.NET MVC 5】第27章 Web API与单页应用程序

    注:<精通ASP.NET MVC 3框架>受到了出版社和广大读者的充分肯定,这让本人深感欣慰.目前该书的第4版不日即将出版,现在又已开始第5版的翻译,这里先贴出该书的最后一章译稿,仅供大家 ...

  4. Detailed ASP.NET MVC Pipeline

    Posted By : Shailendra Chauhan, 27 Jan 2014 P.NET MVC is an open source framework built on the top o ...

  5. Demystifying ASP.NET MVC 5 Error Pages and Error Logging

    出处:http://dusted.codes/demystifying-aspnet-mvc-5-error-pages-and-error-logging Error pages and error ...

  6. 【转】ASP.NET MVC 的最佳实践

    [This post is based on a document authored by Ben Grover (a senior developer at Microsoft). It is ou ...

  7. ASP.NET MVC的Action Filter

    一年前写了一篇短文ASP.NET MVC Action Filters,整理了Action Filter方面的资源,本篇文章详细的描述Action Filter.Action Filter作为一个可以 ...

  8. Professional C# 6 and .NET Core 1.0 - Chapter 41 ASP.NET MVC

    What's In This Chapter? Features of ASP.NET MVC 6 Routing Creating Controllers Creating Views Valida ...

  9. Asp.net MVC Request Life Cycle

    Asp.net MVC Request Life Cycle While programming with Asp.net MVC, you should be aware of the life o ...

随机推荐

  1. Django路由及函数视图

    路由系统 在django中,uri与逻辑函数的对应关系我们称之为路由系统 伪静态 伪静态是相对于静态文件来说的,例如https://www.cnblogs.com/hesujian/p/1116581 ...

  2. canvas验证码实现

    1 <!DOCTYPE html> <html> <!-- head --> <head> <meta charset="utf-8&q ...

  3. pkg-config命令

    返回已安装库文件的元信息 pkg-config读取.pc文件获取信息 基本思想 编译的时候-I指定头文件路径:-L指定库文件路径.这样做总感觉很麻烦 事先把库的位置信息等保存起来,需要的时候再通过特定 ...

  4. Linux下安装php报错:libxml2 not found. Please check your libxml2 installation

    ubuntu/debian: apt-get install libxml2-dev centos/redhat: yum install libxml2-devel

  5. IntelliJ IDEA控制台启动Tomcat输出中文乱码问题

    IntelliJ IDEA控制台输出中文乱码问题 1. 先解决Tomcat中文乱码问题 参考  Tomcat 输出日志出现中文乱码 2. 解决Idea配置问题 打开IntelliJ IDEA本地安装目 ...

  6. C# 普通的辅助类

    在数字前面补0 /// <summary> /// 在数字前面添加0 /// </summary> /// <param name="num"> ...

  7. C语言Makefile文件制作

    本文摘抄自“跟我一起写Makefile ”,只是原文中我自己感觉比较精要的一部分,并且只针对C语言,使用GCC编译器. 原文请看这里:http://wiki.ubuntu.org.cn/%E8%B7% ...

  8. python实现pow函数(求n次幂,求n次方)

    目录 类型一:求n次幂 类型二:求n开方 类型一:求n次幂 实现 pow(x, n),即计算 x 的 n 次幂函数.其中n为整数.pow函数的实现--leetcode 解法1:暴力法 不是常规意义上的 ...

  9. 马的遍历(BFS

    https://www.luogu.org/problemnew/show/P1443 模板BFS...... #include<iostream> #include<cstdio& ...

  10. bloomberg bulkfile 在oracle的存储

    文章导航 bloomberg bulkfile 解析 bloomberg bulkfile 在oracle的存储 一 表名和字段名称的命名规则 1.1. 表名以文件名称直接命名,将文件名中的" ...