Sunday, April 9, 2023

How to register an exception filter globally?

 One can register exception filter globally using following code:

Web API global filters are registered through the HttpConfiguration object available to you in the Register method WebApiConfig.cs if you're using a project template with WebActivator:

public static void Register(HttpConfiguration config)
{
    //stuff before
    config.Filters.Add(new MyWebApiFilter());
    //stuff after
}

or otherwise in the global.asax.cs:

GlobalConfiguration.Configuration.Filters.Add(new MyWebApiFilter());

No comments:

Post a Comment

Web API Versioning.

 Implement the new feature without impacting the existing consumers we can solve this problem by API versioning. When the business has start...