How to exclude one controller action from an authorized filter in ASP.NET MVC 3?

In ASP.NET MVC 3, I can enable AuthorizeAttribute inside Global.asax RegisterGlobalFilters, and this applies to all controller actions. But how can I exclude some controller actions so that these actions can be called without user registration?

EDIT:

Sorry, additional question, if I add authorization in the class, how can I exclude one action?

+4
source share
1 answer

You cannot do this with global filters. Because their name indicates => they are global.

One way is to have all controllers requiring authorization from a common base controller, decorated with the [Authorize] attribute. Controllers that do not require authorization will not receive from this base controller.

Another possibility in ASP.NET MVC 3 is to write a custom IFilterProvider that, based on context, will or will not be set filters. I would recommend you read the following blog post .

+9
source

Source: https://habr.com/ru/post/1346546/


All Articles