I came across a sample MVC3 code which had following in the Global.asax
file:
public static void RegisterGlobalFilters(....)
{
filters.Add(new MyFilter1());
....
var provider = new MyFilterProvider();
provider.Add(c => c.HttpContext.IsDebuggingEnabled ? new MyProvider2() : null);
FilterProviders.Providers.Add(provider)
}
Both MyProvider1
and MyProvider2
are implemented with IResultFilter
, and I am confused why one of them is added to FilterProviders
and the other one is registered as a global filter.
Why and when should we add custom filters on FilterProvider
, and why and when should we register them as global filters?