问题描述
基本上,我正在寻找OnActionExecuting
和OnResultExecuting
之间的比较.
basically i am looking for comparison between OnActionExecuting
and OnResultExecuting
.
什么时候应该使用OnActionExecuting
,什么时候应该使用OnResultExecuting
.
when we should work with OnActionExecuting
and when should work with OnResultExecuting
.
如果有人知道情况,则分享知识.谢谢
if anyone know the situation then share the knowledge. thanks
推荐答案
结果过滤器.它们实现IResultFilter并包装ActionResult对象的执行. IResultFilter声明两个方法:OnResultExecuting和OnResultExecuted. OnResultExecuting在执行ActionResult对象之前运行. OnResultExecuted在结果之后运行,并且可以对结果执行其他处理,例如修改HTTP响应. OutputCacheAttribute类是结果过滤器的一个示例.
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种不同类型的过滤器的事件.
In short, these are events from 2 different types of filters that execute at different times.
IActionFilter.OnActionExecuting
在action方法执行之前 执行. IResultFilter.OnResultExecuting
在之后执行该动作方法(即调用return View()
),但在之前在ActionResult
执行.
IActionFilter.OnActionExecuting
executes before the action method does. IResultFilter.OnResultExecuting
executes after the action method returns (i.e. calls return View()
), but before the ActionResult
executes.
简而言之:OnActionExecuting
可用于在业务逻辑运行之前进行干预. OnResultExecuting
可用于在业务逻辑运行之后和显示逻辑运行之前进行干预.
In plain English: OnActionExecuting
can be used to intervene before the business logic runs. OnResultExecuting
can be used to intervene after the business logic runs and before the display logic runs.
这篇关于ASP.Net MVC操作筛选器:关于用法,OnActionExecuting和OnResultExecuting有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!