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 happen in between these two methods. Like the initialisation of the View Engine, ...
OnActionExecuted – This method is called after a controller action is executed. OnResultExecuting – This method is called before a controller action result is executed. OnResultExecuted – This method is called after a controller action result is executed.
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.
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.
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).
From ActionFilterAttribute.OnResultExecuting Method
Called by the ASP.NET MVC framework before the action result executes.
From ActionFilterAttribute.OnActionExecuted Method
Called by the ASP.NET MVC framework after the action method executes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With