Filters and Action Filters in MVC

Filters and Action Filters in MVC

Introduction

Sometimes we want to perform a certain action before or after a certain operation, or sometimes we need pre- or post-action behaviors from an action, ASP.NET MVC provides a feature called Filters to achieve this functionality.

Types of Filters:-

MVC supports the following types of filters:

• Action filters

• Authorization filters

• Result Filters

• Exception filter

Action Filters:-

Action filters are used to implement logic that is executed before or after a controller action is executed.

Authorization Filters:-

It is used to implement authorization and authentication for action filters

Result Filters:-

Result filters contain logic that is executed before or after the view result is executed.

Exception Filters:-

Exception filters are used to handle errors, either caused by controller actions or controller action results, we can also use them to log exception exceptions.

Action Filters in ASP.NET MVC

Introduction

Action filters can be applied to a controller action or controller, with the help of action filters we can change the way, the action or controller is executed.

MVC provides the following action filters

Output Cache:-

An output cache filter caches the output of an action for a specified period of time.


Handle error:-

It handles errors thrown by an action or controller, redirecting the action to a custom error page if an exception occurs.


Authorize:-

Authorize No Use is used to filter authorized users to access resources.


If we try to access this action it will give below error


Previous Next

Start Your Data Journey Today With MSAInfotech

Take the first step towards data-led growth by partnering with MSA Infotech. Whether you seek tailored solutions or expert consultation, we are here to help you harness the power of data for your business. Contact us today and let’s embark on this transformative data adventure together. Get a free consultation today!

We utilize data to transform ourselves, our clients, and the world.

Partnership with leading data platforms and certified talents

FAQ Robot

How Can We Help?

Captcha

MSA Infotech