Andreas Furster Andreas Furster - 28 days ago 9
ASP.NET (C#) Question

Asp.net Web API - Add attribute to each controller

I have a project with an ASP.net Web API. Now i have created a custom attribute. I can set that attribute for each controller, but how can i set it on each controller at once? Is there something for in the startup class?

Answer Source

Go to the App_Start > WebApiConfig.cs file.

In the Register method add this line:

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