一、應用程式啟動
1.Application_Start方法,程式啟動
2.RegisterRoutes方法,註冊路由
3.System.Web.Mvc.RouteCollectionExtensions.MapRoute方法,出現了MvcRoutehandler對象
二、請求進入
在 “$\Windows\Microsoft.NET\Framework\版本號碼\Config\Web.config“ 中可以找到 " ”
證明請求會經過System.Web.Routing.UrlRoutingModule.Init方法。
1.System.Web.Routing.UrlRoutingModule.Init方法
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方法
3. System.Web.Mvc.MvcRouteHandler.GetHttpHandler方法,返回MvcHandler對象
4.System.Web.Mvc.MvcHandler的構成方法
發現這個類實現了IHttpHandler介面,那麼不得不去看下ProcessRequest方法
5.System.Web.Mvc.MvcHandler.ProcessRequest方法
6.System.Web.Mvc.MvcHandler.ProcessRequestInit方法
返回到第5步
5.System.Web.Mvc.MvcHandler.ProcessRequest方法
6.System.Web.Mvc.ControllerBase.Excete方法
7.System.Web.Mvc.Controller.ExcuteCore方法
8.System.Web.Mvc.Controller.ActionInvoker屬性
9.System.Web.Mvc.Controller.CreateActionInvoker方法
返回了實現IActionInvoker介面的執行個體,返回第7步
7.System.Web.Mvc.Controller.ExcuteCore方法
8.System.Web.Mvc.ControllerActionInvoker.InvokeAction方法
9.System.Web.Mvc.ControllerActionInvoker.InvokeActionResult方法
10.System.Web.Mvc.ActionResult類,封裝一個操作方法的結果
我們來看一下重寫了ExcuteResult的ActionResult的衍生類別:
我們就選ViewResultBase類中的ExcuteResult方法看看
11.System.Web.Mvc.ViewResultBase.ExcuteResult方法
12.System.Web.Mvc.ViewResult.ExcuteResult方法
13.System.Web.Mvc.ViewEngineCollection.FindView方法
14.System.Web.Mvc.VirtualPathProviderViewEngine.FindView方法
返回第13步
13.System.Web.Mvc.ViewEngineCollection.FindView方法
14.System.Web.Mvc.ViewEngineCollection.Find方法
15.System.Web.Mvc.ViewEngineCollection.Find方法
至此,我們得到了ViewEngineResult對象,ViewEngineResult表示定位視圖引擎的結果。
現在我們返回第11步,繼續向下走
11.System.Web.Mvc.ViewResultBase.ExcuteResult方法
12.System.Web.Mvc.BuildManagerCompiledView.Render方法
13. System.Web.Mvc.RazorView.RenderView方法,在這裡使用Razor視圖引擎來展示頁面