简体   繁体   English

Asp.Net Mvc - 在ActionResult.Execute之前或之后调用onactionexecuted吗?

[英]Asp.Net Mvc - does onactionexecuted get called before or after ActionResult.Execute?

Does Controller.OnActionExecuted get called before or after ActionResult.Execute ? ActionResult.Execute之前或之后是否调用Controller.OnActionExecuted

Is there a timeline somewhere of the order in which events occur? 是否存在事件发生顺序的某个时间线? I can't find anything with google-fu alone. 单凭google-fu我找不到任何东西。

The Controller.OnActionExecuted gets called first. 首先调用Controller.OnActionExecuted。

See this post on MSDN, it covers the controller pipeline for MVC. 在MSDN上看到这篇文章 ,它涵盖了MVC的控制器管道。

  1. Receive first request for the application 收到第一个申请请求
  2. Perform routing 执行路由
  3. Create MVC request handler 创建MVC请求处理程序
  4. Create controller 创建控制器
  5. Execute controller 执行控制器
  6. Invoke action 调用动作
  7. Execute result 执行结果

下面的快照显示了执行的执行方式

http://www.asp.net/mvc/overview/older-versions-1/controllers-and-routing/understanding-action-filters-cs http://www.asp.net/mvc/overview/older-versions-1/controllers-and-routing/understanding-action-filters-cs

Action filters contain logic that is executed before and after a controller action executes. 操作过滤器包含在执行控制器操作之前和之后执行的逻辑。 You can use an action filter, for instance, to modify the view data that a controller action returns. 例如,您可以使用操作过滤器来修改控制器操作返回的视图数据。

Result filters contain logic that is executed before and after a view result is executed. 结果过滤器包含在执行视图结果之前和之后执行的逻辑。 For example, you might want to modify a view result right before the view is rendered to the browser. 例如,您可能希望在将视图呈现给浏览器之前修改视图结果。

MVC生命周期

Image Courtesy: - http://www.dotnetinterviewquestions.in/article_explain-mvc-application-life-cycle_210.html 图片礼貌: - http://www.dotnetinterviewquestions.in/article_explain-mvc-application-life-cycle_210.html

Details of Article :- https://www.codeproject.com/Articles/556995/ASP-NET-MVC-interview-questions-with-answers 文章详情: - https://www.codeproject.com/Articles/556995/ASP-NET-MVC-interview-questions-with-answers

Any web application has two main execution steps first understanding the request and depending on the type of the request sending out appropriate response. 任何Web应用程序都有两个主要的执行步骤,首先了解请求,并根据发出适当响应的请求的类型。 MVC application life cycle is not different it has two main phases first creating the request object and second sending our response to the browser. MVC应用程序生命周期没有什么不同,它有两个主要阶段,首先创建请求对象,然后第二个发送我们对浏览器的响应。

Creating the request object: -The request object creation has four major steps. 创建请求对象: - 请求对象创建有四个主要步骤。 Below is the detail explanation of the same. 以下是其详细说明。

Step 1 Fill route: - MVC requests are mapped to route tables which in turn specify which controller and action to be invoked. 步骤1填充路由: - MVC请求映射到路由表,路由表又指定要调用的控制器和操作。 So if the request is the first request the first thing is to fill the route table with routes collection. 因此,如果请求是第一个请求,则首先要使用routes集合填充路由表。 This filling of route table happens in the global.asax file. 路由表的填充发生在global.asax文件中。

Step 2 Fetch route: - Depending on the URL sent “UrlRoutingModule” searches the route table to create “RouteData” object which has the details of which controller and action to invoke. 步骤2获取路由: - 根据发送的URL“UrlRoutingModule”搜索路由表以创建“RouteData”对象,该对象具有要调用的控制器和操作的详细信息。

Step 3 Request context created: - The “RouteData” object is used to create the “RequestContext” object. 步骤3创建请求上下文: - “RouteData”对象用于创建“RequestContext”对象。

Step 4 Controller instance created: - This request object is sent to “MvcHandler” instance to create the controller class instance. 步骤4创建控制器实例: - 将此请求对象发送到“MvcHandler”实例以创建控制器类实例。 Once the controller class object is created it calls the “Execute” method of the controller class. 一旦创建了控制器类对象,它就会调用控制器类的“Execute”方法。

Creating Response object: - This phase has two steps executing the action and finally sending the response as a result to the view. 创建响应对象: - 此阶段有两个步骤执行操作,最后将响应作为结果发送到视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM