Asp.Net MVC Exploring Controllers in depth Part 4. Best Dot Net Training

 Asp.Net MVC Exploring Controllers in-depth Part 4. Best Dot Net Training

MVC – Action Filters

Action filters will apply pre or post Processing logic to a controller action and its result. Action filters are the component we want to use to apply cross-cutting logic to our application i.e. the logic that we must execute across multiple controller actions but we do not want to duplicate the logic inside of the individual controller.

Name Description
OutputCache Cache the output of an Action method.
Authorize Restrict an action or controller to authorize user or role.
ValidateInput Turn on/off the request validation.
ValidateAntiForgeryToken Helps prevent cross site request forgeries.
HandleError Can specify a view to render in the event of an unhandled exception.

                OutputCache: tells the runtime that it allows to cache the final output of the action and use the cached result to serve the future request.

[OutputCache(Duration=10, VaryByParam=”t1″)]

               Authorize: Authorize attribute to allow us to ensure that the user is login before action/controller allow to process the request.

                ValidateInput: To allow or disallow submission of tags and other potentially dangerous content.

              ValidateAntiForgeryToken: If this attribute is provided then cross site submission will not be allowed.

              HandleError: attribute is used to display friendly error pages to the user when something goes wrong.

Edit Web.config as below:

If an exception occurs then it will render the error page which is in the views folder and under the shared folder and is called Error.cshtml file.

Visit for Complet MVC online Training

Leave a Reply

Your email address will not be published. Required fields are marked *