zoukankan      html  css  js  c++  java
  • ASP.NET MVC 请求流程

     一、应用程序启动

      1.Application_Start方法,程序启动

      

    image_thumb8

      2.RegisterRoutes方法,注册路由

      

    image_thumb9

      3.System.Web.Mvc.RouteCollectionExtensions.MapRoute方法,出现了MvcRoutehandler对象

      

    image_thumb111

      二、请求进入

      在 “$WindowsMicrosoft.NETFramework版本号ConfigWeb.config“ 中可以找到 " ”

      证明请求会经过System.Web.Routing.UrlRoutingModule.Init方法。

      1.System.Web.Routing.UrlRoutingModule.Init方法

      

    image_thumb

      2.System.Web.Routing.UrlRoutingModule.PostResolveRequestCache方法

      

      3.System.Web.Routing.RouteCollection.GetRouteData方法

      

      4.System.Web.Routing.Route.GetRouteDara方法

      

      这里的this.RouteHandler就是在第一部分中应用程序启动是实例化好的MvcRouteHandler对象。好了,我们现在已经得到了MvcRouteHandler实例,继续向下走,先返回第2步:

      2.System.Web.Routing.UrlRoutingModule.PostResolveRequestCache方法

      

    image_thumb12

      3. System.Web.Mvc.MvcRouteHandler.GetHttpHandler方法,返回MvcHandler对象

      

    image_thumb15

      4.System.Web.Mvc.MvcHandler的构成方法

      

    image_thumb17

      发现这个类实现了IHttpHandler接口,那么不得不去看下ProcessRequest方法

      5.System.Web.Mvc.MvcHandler.ProcessRequest方法

      

    image_thumb30

      6.System.Web.Mvc.MvcHandler.ProcessRequestInit方法

      

    image_thumb31

      返回到第5步

      5.System.Web.Mvc.MvcHandler.ProcessRequest方法

      

    image_thumb32

      6.System.Web.Mvc.ControllerBase.Excete方法

      

    image_thumb26

      7.System.Web.Mvc.Controller.ExcuteCore方法

      

    image_thumb33

      8.System.Web.Mvc.Controller.ActionInvoker属性

      

    image_thumb29

      9.System.Web.Mvc.Controller.CreateActionInvoker方法

      

    image_thumb28

      返回了实现IActionInvoker接口的实例,返回第7步

      7.System.Web.Mvc.Controller.ExcuteCore方法

      

    image_thumb27

      8.System.Web.Mvc.ControllerActionInvoker.InvokeAction方法

      

    image_thumb7

      9.System.Web.Mvc.ControllerActionInvoker.InvokeActionResult方法

      

    image_thumb91

      10.System.Web.Mvc.ActionResult类,封装一个操作方法的结果

      

    image_thumb10

      我们来看一下重写了ExcuteResult的ActionResult的派生类:

      

    image_thumb11

      我们就选ViewResultBase类中的ExcuteResult方法看看

      11.System.Web.Mvc.ViewResultBase.ExcuteResult方法

      

    image_thumb13

      12.System.Web.Mvc.ViewResult.ExcuteResult方法

      

    image_thumb21

      13.System.Web.Mvc.ViewEngineCollection.FindView方法

      

    image_thumb22

      14.System.Web.Mvc.VirtualPathProviderViewEngine.FindView方法

      

    image_thumb23

      返回第13步

      13.System.Web.Mvc.ViewEngineCollection.FindView方法

      

    image_thumb24

      14.System.Web.Mvc.ViewEngineCollection.Find方法

      

    image_thumb18

      15.System.Web.Mvc.ViewEngineCollection.Find方法

      

    image_thumb19

      至此,我们得到了ViewEngineResult对象,ViewEngineResult表示定位视图引擎的结果。

      现在我们返回第11步,继续向下走

      11.System.Web.Mvc.ViewResultBase.ExcuteResult方法

      

    image_thumb20

      12.System.Web.Mvc.BuildManagerCompiledView.Render方法

      

    image_thumb34

      13. System.Web.Mvc.RazorView.RenderView方法,在这里使用Razor视图引擎来展示页面

      

    image_thumb35
  • 相关阅读:
    编写高效的C#图像处理程序(3) Rgb=>Lab,图像缺陷检测的例子
    使用MvcContrib的FormHelper
    XNA游戏开发
    Microsoft.Web.Mvc Assembly 说明
    NVelocity View Engine with Asp.net Mvc
    Asp.net Mvc Framework可以在Controller中使用的Url.Action方法
    校内网API的.net版本XiaoNei.Net 1.0(非官方)
    Asp.net Mvc Framework在.net 2.0/IIS6下运行,程序示例
    CHSNS#发布V1.21版
    Asp.net Mvc Codeplex Preview 5 第一篇 Helper的新特性
  • 原文地址:https://www.cnblogs.com/rrxc/p/4136640.html
Copyright © 2011-2022 走看看