Jente Rosseel Jente Rosseel - 1 year ago 131
C# Question

Difference between OnActionExecuted and OnResultExecuting

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, ...

Answer Source

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).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download