ASP.NET MVC 請求流程

來源:互聯網
上載者:User

標籤:http   io   ar   os   使用   sp   on   2014   art   

 一、應用程式啟動

  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視圖引擎來展示頁面

  

 

ASP.NET MVC 請求流程

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.