August 2017
Intermediate to advanced
330 pages
7h 26m
English
An Action filter is an attribute that can be applied to a controller or a particular action method.
Action filters implement either the IActionFilter or IAsyncActionFilter interface. They can view and directly modify the result of an action method.
Let's create a simple action filter using the IActionFilter interface. It checks for Header entry publiser-name; if its value does not match Packt, then it returns an action result as BadRequestObjectResult.
Add the CheckPubliserNameAttribute class in ASP.NET Core Web API project. Copy the following code snippet:
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; namespace filters_demo { //Action Filter example public class CheckPubliserNameAttribute : TypeFilterAttribute ...Read now
Unlock full access