Andreas Furster Andreas Furster - 6 months ago 89
ASP.NET (C#) Question Web API - Add attribute to each controller

I have a project with an 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());
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download