Result filters let you execute custom actions before and after the result is processed if an action executes with success. Action results are represented by IActionResult, and we can have code run before and after ExecuteResultAsync is called. Some common uses for result filters include the following:
- Caching (as before)
- Interception (modification of the response)
- Adding response headers
- Result formatting
The IResultFilter interface defines the OnResultExecuting and OnResultExecuted methods. The first takes an instance of ResultExecutingContextas its sole parameter, which offers the following properties:
- Cancel (bool): Whether or not to cancel the processing of the result
- Result (IActionResult): The result to process in case we want to bypass the returned result's execution
- Controller (object): The controller instance
As for the post-event...