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,请求服务器(构建请求报文,并且将请求报文发送 ...
随机推荐
- JavaScript(一基本语法)
本篇博客是对js的一个基本的了解,对于没有js基础的同学来说应该是个入门的基本吧 javascript 是原型化继承来的面向对象的动态类型的区分大小写的客户端的脚本语言.主要目的是为了解决服务器语言, ...
- 三次握手wireshark抓包分析,成功握手和失败握手
启动 点击start出现下面的对话框 wireshark是捕获机器上的 某一块网卡的网络包,当机器上有多块网卡的时候,需要选择一个网卡进行捕获操作. 选择网卡 >主页面上,直接点击选中后star ...
- 居然还有FindFirstChangeNotification函数
http://download.csdn.net/download/sololie/5966243
- System单元对所有与COM相关的声明就这么多,需要倒背如流
是首先是VM表,但是和COM相关的函数地址都废弃了,这几个VM函数具体放在哪里,还得在研究: { Virtual method table entries } vmtSelfPtr = -; vmtI ...
- eclipse设置关联文件打开方式
window->preferences: General->Editors->File Associations
- bzoj2301(莫比乌斯反演+分块)
传送门:2301: [HAOI2011]Problem b 题意:对于给出的n个询问,每次求有多少个数对(x,y),满足a≤x≤b,c≤y≤d,且gcd(x,y) = k,gcd(x,y)函数为x和y ...
- C语言文件操作之fgets()
来说一说fgets(..)函数. 原型 char * fgets(char * s, int n,FILE *stream); 參数: s: 字符型指针, ...
- Wix学习整理(2)——HelloWorld安装添加UI
原文:Wix学习整理(2)--HelloWorld安装添加UI 在前一篇随笔Wix学习整理(1)——快速入门HelloWorld中,我们制作的安装包安装界面太简单,没有与用户进行交互的过程.下面我们修 ...
- hdu3033(变形分组背包)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3033 题意:Iserlohn要买鞋,有k种牌子,每种牌子至少买一双鞋子.每双鞋子有标价跟实际价值.求用 ...
- mongodb - 前端form表单数据传输,在保存和清除的数据格式的处理程序的 - 非递归
//处理时间段,将ISODate("2014-10-09T18: 37: 50.0Z") 兑换 2014-10-09 18:37:50这样的格式 //截至处理6层树形结构数据,当多 ...