MVC中的执行流程

发布于 2024-08-16 23:10:13 字数 137 浏览 5 评论 0原文

我正在尝试详细学习 MVC,我想知道内部的确切功能流程是什么,即调用哪些函数(重要函数)以及它们做什么应用程序何时启动以及除了我们在继续进行时在应用程序中编写的控制器操作之外还调用了哪些函数。

I am trying to learn MVC in detail, and I am wondering what's the exact functional flow internally, in the sense of which functions (important functions) are called and what they do when the application starts and what functions are called apart from the controller actions that we write in our application as we proceed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

停滞 2024-08-23 23:10:13

以下是详细步骤:

  1. 请求进入 ASP.NET
  2. ASP.NET 路由通过调用 RouteCollection.GetRouteData
  3. 这又调用 RouteBase.GetRouteData 在每个路由上,直到找到
  4. 匹配项 匹配路由的 IRouteHandler 有其 GetHttpHandler 调用
  5. MvcHandler 的方法运行 (ProcessRequest 被调用)
  6. MVC 控制器工厂在 CreateController
  7. ControllerActionInvoker 确定要在 InvokeAction
  8. AuthorizationFilter 阶段执行(这包括控制器本身的授权方法)
  9. ActionExecuting 阶段执行
  10. 请求的操作方法执行
  11. ActionExecuted 阶段
  12. 如果存在结果对象,则 ResultExecuting 阶段执行
  13. 如果结果未取消,则执行 ActionResult 的 ExecuteResult 方法被执行
  14. ResultExecuted 阶段执行
  15. 如果发生错误,则 Exception 阶段执行

我还想向您推荐 MVC 蛇形图,我在 ASP.NET MVC 的许多演示中使用它。这是完整图片: alt text

我链接到的博客文章描述了 ASP.NET MVC 中使用的一些有关数据如何流经应用程序的概念。

Here are the detailed steps:

  1. Request comes into ASP.NET
  2. ASP.NET Routing finds the route match by calling RouteCollection.GetRouteData
  3. This in turn calls RouteBase.GetRouteData on each route until it finds a match
  4. The IRouteHandler for the matching route has its GetHttpHandler method called
  5. The MvcHandler runs (ProcessRequest is called)
  6. The MVC controller factory locates and creates the controller in CreateController
  7. The ControllerActionInvoker determines which action to run in InvokeAction
  8. The AuthorizationFilter stage executes (this includes the authorization method on the controller itself)
  9. The ActionExecuting stage executes
  10. The requested action method is executed
  11. The ActionExecuted stage executes
  12. If there is a result object then the ResultExecuting stage executes
  13. If the result wasn't cancelled then the ActionResult's ExecuteResult method is executed
  14. The ResultExecuted stage executes
  15. If an error occured then the Exception stage executes

I would also like to refer you to the MVC Snake Diagram that I use in many presentations on ASP.NET MVC. Here's the full image: alt text

The blog post I linked to describes some of the concepts used in ASP.NET MVC regarding how data flows through the application.

温柔少女心 2024-08-23 23:10:13

查看 Redgates 的免费“ASP.NET MVC 请求处理管道" 执行流程海报

Steven Sanderson 的 MCV 书 了解详细信息。

Check out Redgates's free "The ASP.NET MVC Request Handling Pipeline" poster for execution flow

and Steven Sanderson's MCV book for details.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文