May 2018
Intermediate to advanced
334 pages
7h 25m
English
With the help of the filter attribute, you can implement security at the context level. In this section, we will rewrite our model and API resources to implement filters/attributes.
In the previous section, we used the Required attribute with our Product model, and this did not work for us. In this section, we will fix the problem with the help of filters (for more information on filters, go to https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/filters).
Lets add a custom filter that validates the input, detecting whether any of the required fields are missing. If they are, it will just throw an exception. You need to modify the previous code, changing the Product model to the following:
[Required(ErrorMessage = ...