Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Authorize Action filter and Authorization filter?

As per the ASP.NET website

The ASP.NET MVC framework includes several action filters:

  1. OutputCache – This action filter caches the output of a controller action for a specified amount of time.
  2. HandleError – This action filter handles errors raised when a controller action executes.
  3. Authorize – This action filter enables you to restrict access to a particular user or role.

Also, there is a type of filter in MVC called "Authorization filter".

I am confused whether [Authorize] attribute is an Action filter or Authorization filter? And when will it be executed ?

like image 384
DfrDkn Avatar asked Jun 25 '16 13:06

DfrDkn


People also ask

What is Authorize filter?

Authorization filters allow you to perform authorization tasks for an authenticated user. A good example is Role based authorization. ASP.NET MVC 4 also introduced a built-in AllowAnonymous attribute. This attribute allows anonymous users to access certain Controllers/Actions.

Why do we use authorization filters?

Authorization filters are used to authenticate whether the user requested action method in the controller is authorized to access or not and for validating properties of the request. Authorization filters run before any other filter. Generally, we will use authorization filters like as shown below.


1 Answers

What is the difference between Authorize Action filter and Authorization filter?

None.

That documentation is apparently incorrect (and if you note in the table of contents, it is for version 1 and 2 of MVC, so it is also out of date).

AuthorizeAttribute inherits IAuthorizationFilter, so it is in fact an authorization filter, not an action filter. There is no Authorization action filter in MVC.

Note that for MVC 3 to MVC 5 you should refer to the up-to-date Filtering in ASP.NET MVC documentation in the future.

And when will it be executed ?

As per MSDN:

Filters run in the following order:

  1. Authorization filters
  2. Action filters
  3. Response filters
  4. Exception filters
like image 98
NightOwl888 Avatar answered Sep 28 '22 06:09

NightOwl888