The widespread logic from the API is fully pulled into filters, which are used the place ideal, so that the function on the controller is as uncomplicated as is possible.
You ought to constantly conduct details validation and sanitization In order to circumvent vulnerabilities such as injection assaults Any time filters connect with person enter.
The type of outcome being executed depends on the motion in issue. An MVC action returning a perspective would come with all razor processing as Component of the ViewResult getting executed. An API technique might conduct some serialization as Section of the execution of the result. Find out more about motion effects
If each asynchronous and synchronous interfaces are implemented in a single class, just the async system is referred to as. When employing abstract lessons like ActionFilterAttribute, override only the synchronous techniques or maybe the asynchronous procedures for each filter type.
Loggers are offered from DI. Nonetheless, avoid developing and making use of filters purely for logging applications. The created-in framework logging typically supplies what's essential for logging. Logging included to filters:
Quite a few on the filter interfaces have corresponding attributes which might be used as foundation courses for tailor made implementations.
This doc relates to Razor Webpages, API controllers, and controllers with sights. Filters Will not perform straight with Razor factors. A filter can only indirectly have an impact on a element when:
You also can make your own private custom made action filters. By way of example, it is advisable to make a personalized motion filter in an effort to put into practice a personalized authentication process. Or, it is advisable to make an action filter that modifies the check out information returned by a controller motion.
Consequence filters are only executed when an action or motion filter generates an motion consequence. Outcome filters aren't executed when:
Such as, the information controller in Listing one exposes an action named Index() that returns The existing time. This action is decorated with the OutputCache filters in asp.net mvc motion filter. This filter leads to the worth returned through the motion for being cached for ten seconds.
We are able to use Final result filters to operate code prior to or once the execution of controller action effects. They are executed only if the controller action system is executed efficiently. We can easily publish logic to encompass the view or to apply some customizations to all of the action results in our software.
WhereIf provides far more declarative way, if you don't need to utilize extensions you can just filter like that:
Logging the tip on the Action: This concept (indicating the completion on the motion and its period) is then logged utilizing the very same logging services.
My sample software is configured to work with an in-memory Entity Framework Core DbContext, but although it ended up utilizing SQL Server, I could conveniently change to using an in-memory retail outlet for my integration exams.