Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing Authentication Filters in ASP.NET Web API 2

I have a WebAPI project currently that implements the [Authorize] on all methods globally by adding the following code in my Startup.cs. This is a great

config.Filters.Add(new AuthorizeAttribute());

Can I dynamically remove this attribute from selected methods? Is there a way to do this or would I have to manually apply to the end points?

The only other solution I can think of is to have a flag on that attribute, but then it would be applied twice which would make no sense.

Thanks!

like image 511
NewZeroRiot Avatar asked Sep 08 '15 13:09

NewZeroRiot


1 Answers

You can use [AllowAnonymous] attribute for disabling Authorization. This attribute is for classes, methods etc.

like image 119
Arda Güçlü Avatar answered Oct 25 '22 02:10

Arda Güçlü