Action filters are invoked before and after an action method is called, so they can be used, for example, to do the following:
- Cache results
- Modify parameters
- Modify results
Now, we already have the parameters to the action method, which come from the value providers. Here, the filter interfaces are IActionFilter and IAsyncActionFilter. The synchronous one offers two methods, OnActionExecuting and OnActionExecuted. They are for pre-event and post-event notifications. OnActionExecuting takes a single parameter of the ActionExecutingContext type, offering the following properties:
- Result (IActionResult): Set a value here to short-circuit the request processing pipeline and return a value to the client, without actually executing the action.
- ActionArguments (IDictionary<string, object>): The parameters of the action method.
- Controller...