当前位置: 移动技术网 > IT编程>开发语言>.net > ASP.NET MVC 请求流程

ASP.NET MVC 请求流程

2019年05月10日  | 移动技术网IT编程  | 我要评论
  一、应用程序启动   1.application_start方法,程序启动      2.registerroutes方法,注册路由      3.system.web

  一、应用程序启动

  1.application_start方法,程序启动

  

image_thumb8

  2.registerroutes方法,注册路由

  

image_thumb9

  3.system.web.m.routecollectionextensions.maproute方法,出现了mvcroutehandler对象

  

image_thumb111

  二、请求进入

  在 “$\windows\microsoft.net\framework\版本号\config\web.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

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网