gpt4 book ai didi

asp.net-mvc - ASP.Net MVC 操作过滤器 : What is the difference between OnActionExecuting and OnResultExecuting regarding usage

转载 作者:行者123 更新时间:2023-12-05 01:13:45 25 4
gpt4 key购买 nike

我正在寻找 OnActionExecuting 之间的比较和 OnResultExecuting .
什么时候应该与 OnActionExecuting 一起工作,以及与 OnResultExecuting 一起使用时?

最佳答案

来自 Filtering in ASP.NET MVC :

  • Action filters. These implement IActionFilter and wrap the action method execution. The IActionFilter interface declares two methods: OnActionExecuting and OnActionExecuted. OnActionExecuting runs before the action method. OnActionExecuted runs after the action method and can perform additional processing, such as providing extra data to the action method, inspecting the return value, or canceling execution of the action method.

  • Result filters. These implement IResultFilter and wrap execution of the ActionResult object. IResultFilter declares two methods: OnResultExecuting and OnResultExecuted. OnResultExecuting runs before the ActionResult object is executed. OnResultExecuted runs after the result and can perform additional processing of the result, such as modifying the HTTP response. The OutputCacheAttribute class is one example of a result filter.


简而言之,这些事件来自在不同时间执行的 2 种不同类型的过滤器。 IActionFilter.OnActionExecuting在 action 方法执行之前执行。 IResultFilter.OnResultExecuting在 action 方法返回之后执行(即调用 return View() ),但在 ActionResult 之前执行执行。
简单的英语: OnActionExecuting可用于在业务逻辑运行之前进行干预。 OnResultExecuting可用于在业务逻辑运行之后和显示逻辑运行之前进行干预。

关于asp.net-mvc - ASP.Net MVC 操作过滤器 : What is the difference between OnActionExecuting and OnResultExecuting regarding usage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36099640/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com