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. 前端编译原理 简述-jison

    最近几年的项目技术难点都和编译原理,抽象语法树,代码编辑器 有关系.现在时间有点空,先从基础了解起来,让有些交互和提示能够更智能些. 编译原理-Parser    编译原理 其实就是 让计算机懂的 “ ...

  2. 【转载】salesforce 零基础开发入门学习(五)异步进程介绍与数据批处理Batchable

    salesforce 零基础开发入门学习(五)异步进程介绍与数据批处理Batchable   本篇知识参考:https://developer.salesforce.com/trailhead/for ...

  3. 开发六年mybatisplus使用小结

    最近在项目里用到了一个第三方库,叫mybatisplus,是一个mybatis的增强库,简单来说就是增强了mybatis的功能,让mybatis更好用,mybatisplus给的官方定义是Mybati ...

  4. 面试总结关于Spring面试问题(精选)

    1.什么是Spring? Spring是一个反转控制IOC和AOP的开发框架和平台. 2.解释一下Spring? 轻量 : Spring 在大小和透明度上是轻量的,Spring基本核心版本大概只有1M ...

  5. django_redis

    目录 下载 说明 补充: 内存中设置值 取值 使用 配置: settings/dev.py缓存配置 - redis存储:依赖 django-redis,要安装>>>pip insta ...

  6. grafana根据不同prometheus server统计数据

    场景:由于采集的数据量巨大,所以部署了多台prometheus server服务器.根据业务领域分片采集,减轻prometheus server单节点的压力. 问题:grafana如何同时显示多数据源 ...

  7. aiops常用算法

    1.数据聚合/关联技术 概念聚类算法AOI分类算法K近邻/贝叶斯分类器/logistic回归(LR)/支持向量机(SVM)/随机森林(RF) 2.数据异常点检测技术独立森林算法 3.故障诊断和分析策略 ...

  8. CSS3媒体查询实例

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  9. python_模块2

    1.sys模块 import sys # 获取一个值的应用计数 a = [11,22,33] b = a print(sys.getrefcount(a)) # python默认支持的递归数量 v1 ...

  10. python 获取指定字符前面或后面的所有字符

    要求:获取某个字符指定字符的前面或后面的所有字符内容 示例: URL = https://www.baid/v2/user/login (1)想要获取v2的数据:v2/user/login print ...