MVC4 源码分析(Visual studio 2012/2013)
HttpModule中重要的UrlRoutingModule
9:this.);
10:this.(context);
IRouteHandler routeHandler = routeData.RouteHandler; //根据路由数据创建出了MvcRouteHandlerIHttpHandler httpHandler = routeHandler.GetHttpHandler(requestContext);
根据MvcRouteHandler创建出了MvcHandler:IHttpHandler(MvcHandler实现了IHttpHandler接⼝,接下来就要进⼊MVC源代码分析)在MVC4源代码src⽂件夹System.Web.Mvc类库下MVC4百度云源代码:链接: 密码:4tivReflector7百度云盘:链接: 密码:gyx01:routeHandler.(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>视图呈现
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- huatuo3.com 版权所有 蜀ICP备2023022190号-1
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务