Saturday, 22 December 2018

What are filters in ASP.NET MVC / Action Filters

Action Filters are the attributes that are applied to the Controller Class or Controller Action Method to add pre and post processing logic. When applied at the controller level, they are applicable for all actions within that controller and when applied on controller action method, they are applicable to that method only. All total action filters provide extra features to the controller class and its action methods.

Examples of few Action Filters are

Authorize: Provides windows and forms authentication
ChildActionOnly: Restricts action methods not to be accessed using URL
HandleError: Used to handle errors
OutputCache: Used to cache data or for partial page postback
RequireHttps: Enforces an HTTP request to pass HTTPS
ValidateInput: Enables and disable HTML encoding.
ValidateAntiForgeryToken: Restricts anti-forgery tokens in your application.

You can also create your own custom filters if filters provided by ASP.Net MVC will not full fill your requirement.

No comments:

Post a Comment