MVC4 源码分析(Visual studio 2012/2013)

HttpModule中重要的UrlRoutingModule

9:this.OnApplicationPostResolveRequestCache);

10:this.PostResolveRequestCache(context);

IRouteHandler routeHandler = routeData.RouteHandler; //根据路由数据创建出了MvcRouteHandler

IHttpHandler httpHandler = routeHandler.GetHttpHandler(requestContext);

根据MvcRouteHandler创建出了MvcHandler:IHttpHandler(MvcHandler实现了IHttpHandler接口,接下来就要进入MVC源代码分析)

在MVC4源代码src文件夹System.Web.Mvc类库下

MVC4百度云源代码:链接:http://pan.baidu.com/s/1pLDvXB9  密码:4tiv

Reflector7百度云盘:链接:http://pan.baidu.com/s/1eSm9Y06  密码:gyx0

1:routeHandler.GetHttpHandler(requestContext);

2:MvcHandler.cs  ProcessRequest方法

通过工厂模式创建MVC中的Controller控制器,然后执行Execute方法

3:controller.Execute(RequestContext);

IController是接口,需要找具体实现类(之前通过工厂模式创建Controller控制器,优先去找Controller类)

Controller : ControllerBase  //Controller并没有实现IController接口,找其父类

ControllerBase : IController  //ControllerBase实现了IController接口

4:ExecuteCore()  //Controller类中

5:ActionInvoker.InvokeAction(ControllerContext, actionName)方法

ControllerActionInvoker : IActionInvoker  //ControllerActionInvoker 实现了IActionInvoker  接口

6:InvokeActioin

1:InvokeActionMethodWithFilters

1.1:InvokeActionMethod

2:InvokeActionResultWithFilters

2.1:InvokeActionResultFilterRecursive

2.2:InvokeActionResult

7:actionResult.ExecuteResult(controllerContext);

ViewResult : ViewResultBase   //ViewResult 并没有实现ActionResult接口,找其父类

ViewResultBase : ActionResult  //ViewResultBase实现了ActionResult接口

8:View.Render(viewContext, writer); 渲染View视图【WebForm.aspx视图引擎】

WebFormView : BuildManagerCompiledView  //WebFormView 并没有实现IView接口,找其父类

BuildManagerCompiledView : IView  //BuildManagerCompiledView实现了IView接口

8.1:BuildManagerCompiledView (WebForm.aspx视图引擎模式)

RenderView为抽象类,由其子类实现具体方法内容

执行ASP.NET 页面生命周期ProcessRequest方法,把后续第13/第14等事件执行完毕,然后把Render渲染好的所有html代码返回给浏览器

Application  19事件

ASP.NET MVC源码分析

1:获取ControllerFacotry,根据上下文反射Controller对象

  在Mvchandler的PR方法中

2:调用controller.Execute方法

  在MvcHandler的PR方法中

3:调用ActionInvoker.InvokeAction方法

  当前Controller类 -->ControllerBase类的Execute方法-->Controller类的ExecuteCore方法

4:调用InvokeActionResultWithFilter

  ActionInvoker对象为ControllerActionInvoker类的实例

5:调用actionResult.ExecuteResult

6:调用View.Render方法,将页面渲染到输出流中

  ViewResult类-->ViewResultBase类

当一个asp.net mvc应用程序提出请求,为了响应请求,包含一些请求执行流程步骤!在asp.net mvc应用程序Http request和Http Response过程中,

主要包含8个步骤:

1>RouteTable(路由表)的创建

2>UrlRoutingModule 请求拦截

3>Routing engine 确定route

4>route handler 创建相关的IHttpHandler实例

5>IHttpHandler实例确定Controller(控制器)

6>Controller执行

7>一个视图引擎创建

8>视图呈现

ASP.NET MVC源码分析的更多相关文章

  1. asp.net mvc源码分析-DefaultModelBinder 自定义的普通数据类型的绑定和验证

    原文:asp.net mvc源码分析-DefaultModelBinder 自定义的普通数据类型的绑定和验证 在前面的文章中我们曾经涉及到ControllerActionInvoker类GetPara ...

  2. asp.net mvc源码分析-ModelValidatorProviders 客户端的验证

    几年写过asp.net mvc源码分析-ModelValidatorProviders 当时主要是考虑mvc的流程对,客户端的验证也只是简单的提及了一下,现在我们来仔细看一下客户端的验证. 如图所示, ...

  3. ASP.NET MVC 源码分析(一)

    ASP.NET MVC 源码分析(一) 直接上图: 我们先来看Core的设计: 从项目结构来看,asp.net.mvc.core有以下目录: ActionConstraints:action限制相关 ...

  4. asp.net MVC 源码分析

    先上一张图吧 asp.net请求机制的图  by传智播客邹华栋老师 然后是 邹老师添加MVC请求过程的图 其实MVC 是在.netframework上加了一个过滤器  HttpModule 在C:\W ...

  5. asp.net mvc源码分析-Route的GetRouteData

    我知道Route这里东西应该算路由,这里把它放到mvc里面有些不怎么合适,但是我想大家多数遇到路由都是在mvc的时候吧.首先我们还是来看看GetRouteData方法吧 [csharp] public ...

  6. asp.net mvc源码分析-Action篇 IModelBinder

    我们首先还是看看ReflectedParameterBindingInfo的Binder属性吧: public override IModelBinder Binder {            ge ...

  7. ASP.NET MVC源码分析系列

    Controller下的JsonResult的ExecuteResult方法 public override void ExecuteResult(ControllerContext context) ...

  8. ASP.NET MVC 源码分析(二) —— 从 IRouteBuilder认识路由构建

    我们来看IRouteBuilder的定义: public interface IRouteBuilder { IRouter DefaultHandler { get; set; } IService ...

  9. ASP.NET WebForm / MVC 源码分析

    浏览器 Url:https//localhost:6565/Home/Index ,https//localhost:6565/WebForm1.aspx,请求服务器(构建请求报文,并且将请求报文发送 ...

随机推荐

  1. Php 解析XML文件

    Php 解析XML文件 Php 解析XML文件,仅供学习參考!演示样例代码例如以下: <?php header("Content-type: text/html; charset=ut ...

  2. Swift - 各种手势检测大全(UIGestureRecognizer及其子类)

    UIGestureRecognizer有许多子类,用于监听一些常见的手势事件,这些子类主要有: 1,UISwipeGestureRecognizer:滑动(快速移动) 1 2 3 4 5 6 7 8 ...

  3. Js正则表达式学习之test和compile的简单介绍

    RegExp 对象用于规定在文本中检索的内容. 定义 RegExp RegExp 对象用于存储检索模式. 通过 new 关键词来定义 RegExp 对象.以下代码定义了名为 patt1 的 RegEx ...

  4. HDU 1007 近期点对

    分治法求近期点对 递归将点不断分成小组.计算最短距离.此时的最短距离不过两点都属两块的某一块(这里的切割点是mid点). 还须要考虑两点分属两块的情况. 这时对于选点则把范围缩小到了以mid为中心. ...

  5. Twenty Newsgroups Classification实例任务之TrainNaiveBayesJob(一)

    接着上篇blog,继续看log里面的信息如下: + echo 'Training Naive Bayes model' Training Naive Bayes model + ./bin/mahou ...

  6. 一个通用onReady函数的实现

    define([], function(){ function onReady(fn) { var DOC = document, html = DOC.documentElement, W3C = ...

  7. 它们的定义iOS双击Home截图按键开关

    <pre name="code" class="objc"><p>双击假设Home,我会去iOS App的switcher页面,这里列出 ...

  8. 怎样用js得到当前页面的url信息方法(JS获取当前网址信息)

    设置或获取对象指定的文件名称或路径.window.location.pathname 设置或获取整个 URL 为字符串.window.location.href; 设置或获取与 URL 关联的端口号码 ...

  9. HDU1300DP

    /* HDU1300 DP 特定n饰品种类 每个饰品的两个数据.amount[i]代表数量.price[i]代表单位价格 购买珠宝时要满足下面购买规则: 单独买:每种珠宝要加上数量10 合并买:能够把 ...

  10. 利用objc的runtime来定位次线程中unrecognized selector sent to instance的问题

    昨天遇到一个仅仅有一行错误信息的问题: -[NSNull objectForKey:]: unrecognized selector sent to instance 0x537e068 因为这个问题 ...