Difference between OnActionExecuted and OnResultExecuting

后端 未结 3 515
小鲜肉
小鲜肉 2021-01-01 08:29

What is the difference between OnActionExecuted and OnResultExecuting? Do they both get fired right after each other once the action has been processed or does something hap

3条回答
  •  遥遥无期
    2021-01-01 09:07

    They have a different context.

    OnActionExecuted has a ActionExecutedContext in which you can view the result produced by the action. You can also see whether the action encountered an Exception and see if the exception was handled.

    OnResultExecuting has a ResultExecutingContext. This method gets called just before the ActionResult instance is invoked. You can examine the result of the method and possibly cancel the execution of the result. This will usually result in a blank response with status code 200. (you can't do this in the OnActionExecuted method).

提交回复
热议问题