ASP.NET MVC源码分析
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源码分析的更多相关文章
- asp.net mvc源码分析-DefaultModelBinder 自定义的普通数据类型的绑定和验证
原文:asp.net mvc源码分析-DefaultModelBinder 自定义的普通数据类型的绑定和验证 在前面的文章中我们曾经涉及到ControllerActionInvoker类GetPara ...
- asp.net mvc源码分析-ModelValidatorProviders 客户端的验证
几年写过asp.net mvc源码分析-ModelValidatorProviders 当时主要是考虑mvc的流程对,客户端的验证也只是简单的提及了一下,现在我们来仔细看一下客户端的验证. 如图所示, ...
- ASP.NET MVC 源码分析(一)
ASP.NET MVC 源码分析(一) 直接上图: 我们先来看Core的设计: 从项目结构来看,asp.net.mvc.core有以下目录: ActionConstraints:action限制相关 ...
- asp.net MVC 源码分析
先上一张图吧 asp.net请求机制的图 by传智播客邹华栋老师 然后是 邹老师添加MVC请求过程的图 其实MVC 是在.netframework上加了一个过滤器 HttpModule 在C:\W ...
- asp.net mvc源码分析-Route的GetRouteData
我知道Route这里东西应该算路由,这里把它放到mvc里面有些不怎么合适,但是我想大家多数遇到路由都是在mvc的时候吧.首先我们还是来看看GetRouteData方法吧 [csharp] public ...
- asp.net mvc源码分析-Action篇 IModelBinder
我们首先还是看看ReflectedParameterBindingInfo的Binder属性吧: public override IModelBinder Binder { ge ...
- ASP.NET MVC源码分析系列
Controller下的JsonResult的ExecuteResult方法 public override void ExecuteResult(ControllerContext context) ...
- ASP.NET MVC 源码分析(二) —— 从 IRouteBuilder认识路由构建
我们来看IRouteBuilder的定义: public interface IRouteBuilder { IRouter DefaultHandler { get; set; } IService ...
- ASP.NET WebForm / MVC 源码分析
浏览器 Url:https//localhost:6565/Home/Index ,https//localhost:6565/WebForm1.aspx,请求服务器(构建请求报文,并且将请求报文发送 ...
随机推荐
- Cocos2d-x layout (二)
相对某个控件进行布局 Size widgetSize = Director::getInstance()->getWinSize(); Text* alert = Text::create(&q ...
- Ogre嵌入MFC傻瓜全然教程(三)
经过前两两篇博文的解说.我们已经完毕了渲染工作,但仅仅是渲染而没有交互性,本篇博文我们就来加上事件的处理方法. 首先我们须要为项目加入一个帧监听类:CMyFrameListener,为了直观,在这直接 ...
- Delphi读写UTF-8、Unicode格式文本文件
// UTF-8文件写入函数procedure SaveUTFFile(const FileName: string; S: string; WriteHeader: Boolean = True); ...
- Next-Key Locks
Next-Key Locks 一个next-key lock 是 一个record lock 在index record 和 一个区间锁 在一个区间在index record之前 InnoDB 执行 ...
- premake 在64位Ubuntu系统下编译32位GCC程序
首先,要安装GCC 4.8, 参考前文:Ubuntu 12.04 & 13.04 安装 GCC4.8.1 其中,重点是安装multilib apt-get install gcc-4.8-mu ...
- Android 进行单元測试难在哪-part3
原文链接 : HOW TO MAKE OUR ANDROID APPS UNIT TESTABLE (PT. 1) 原文作者 : Matthew Dupree 译文出自 : 开发技术前线 www.de ...
- 主流JavaScript框架(Dojo、Google Closure、jQuery、Prototype、Mootools和YUI)的分析和对比
本文主要选取了目前比较流行的JavaScript框架Dojo.Google Closure.jQuery.Prototype.Mootools和YUI进行对比,主要是根据网上的资料整理而成,希望可以供 ...
- SuSE(SLES)安装配置syslog-ng日志server,可整合splunk
Update History 2014年04月25日 - 撰写初稿 引言 在自己主动化部署AutoYast.自己主动化监控BMC Patrol双方面形成雏形后.日志的收集.管理.分析也顺势成为我们须要 ...
- 鼠标右键怎么清除Catalyst Control Center
开始→运行→regedit→找到HKEY_CLASSES_ROOT\Directory\Background\shellex\ContextMenuHandlers\ACE→双击并修改其键值 可以删除 ...
- oracle事务(转)
今天温习oracle事务,记录如下: 事务定义 事务是保持数据的一致性,它由相关的DDL或者DML语句做为载体,这组语句执行的结果要么一起成功,要么一起失败. 我们 ...