zoukankan      html  css  js  c++  java
  • 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>视图呈现

  • 相关阅读:
    Silverlight MMORPG WebGame游戏设计(三)Server和Client的暗号
    Silverlight MMORPG WebGame游戏设计(七)IsolatedStorage,想说爱你不容易
    如何在WP7上用XNA写2D游戏(四)
    Silverlight MMORPG WebGame游戏设计(六)Server和Client的婚后协议[附上完整15M游戏DEMO]
    我的2010年
    如何在WP7上用XNA写2D游戏(一)
    笑话一片
    设计模式简单概括总结2
    设计模式简单概括总结
    ExtJs 4 动态加载grid
  • 原文地址:https://www.cnblogs.com/DrHao/p/5315556.html
Copyright © 2011-2022 走看看