一、应用程序启动

  1.application_start方法,程序启动

  

  2.registerroutes方法,注册路由

  

  3.system.web.m.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视图引擎来展示页面