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. 1 使用webpack搭建vue开发环境

    1 先去node.js官网下载nodejs并且安装 安装成功之后在命令行输入node -v 回车,npm -v回车如果显示对应的版本号,说明node安装成功,自带的npm也安装成功 2 在d盘下创建一 ...

  2. Python 多进程拷贝文件夹案例

    import os import multiprocessing def copy_file(q, file_name, old_folder_name, new_folder_name): &quo ...

  3. 日语单词N3_N4_N5

    单 词 讲 解 あ行单词 ああ:0[副]那样.那种 例句:ああ言うことはしないほうがいい.那样的事情最好不做. 電車の窓からごみを棄てているああ言うことはしないほうがいい. 挨拶(あいさつ):① 寒暄 ...

  4. 13.MyBatis注解式开发

    mybatis 的注解,主要是用于替换映射文件.而映射文件中无非存放着增.删.改.查 的 SQL 映射标签.所以,mybatis 注解,就是要替换映射文件中的 SQL 标签. mybatis 官方文档 ...

  5. h5 移动端开发自适应 meta name="viewport"的使用总结

    本文系个人理解,可能有误差,仅供参考,谨慎采纳! 布局视口: 系统自带 一般大于屏幕宽度 理想宽度:  设置页面的viewport 的一个宽度,使不同的手机的布局视口宽度尽量接近可视窗口的值: 可视视 ...

  6. js 四 windows对象

    1 window 对象 1 window对象的属性 window对象的属性,又都是对象类型的 1 screen 对象 访问screen 对象 et: console.log(window.screen ...

  7. TLS1.3&TLS1.2形式化分析(二)

    1.下面是TLS1.2和TLS1.3握手协议过程 ,明显的可以看出存在不同 . 我们先说TLS1.2的握手过程明显是比TLS1.3的握手过多了一次.在TLS1.3中舍弃了之前RSA的协商过程,然后基于 ...

  8. 12 Windows编程——子窗口和系统内置窗口类“BUTTON”

    创建子窗口类,使得子窗口有自己的处理过程. 子窗口类型WS_CHILD不能和WS_POPUP一起使用!为什么子窗口要有自己的处理过程?如果使用主窗口类来创建子窗口,那么子窗口和主窗口将公用窗口处理过程 ...

  9. zabbix low-level discovery 监控mysql

    当一台服务器上MySQL有多个实例的时候,MySQL占用多个不同端口.利用zabbix的low-level discovery可以轻松监控. 思路参考:http://dl528888.blog.51c ...

  10. webstorm 2018.2.5最新激活方式

    亲测时间    2019年6月27日  08:45:52 下载破解文件: https://pan.baidu.com/s/1CMh5AYgewZflMVWL9BO-hA 打开webstorm / bi ...