Web API uses a completely different filter infrastructure than MVC. As a result, you will not be able to use MVC's FilterAttributeFilterProvider class to change the behavior of Web API. Instead, you will have to create a provider implementing the Web API-specific
IFilterProvider interface. The provider implementation that is responsible for returning filters registered via filter attributes is the
ActionDescriptorFilterProvider class.
Also on another note, am I redirected to the login page when I am not authorized for an apiController? I was under the impression that the webAPI would return a 401.
Also on another note, am I redirected to the login page when I am not authorized for an apiController? I was under the impression that the webAPI would return a 401.
That's a bug in the Web API Beta when you are hosting in an ASP.NET application. It should be fixed for the next release.
.nettim
0 Points
6 Posts
FilterAttributeFilterProvider not firing for AuthorizationFilterAttribute
Apr 06, 2012 08:03 PM|LINK
I am attempting to use FilterAttributeFilterProvider to inject dependencies into my AuthorizationFilterAttribute of the web api.
The provider fires for MVC however, the FilterAttributeFilterProvider is not firing for the AuthorizationFilterAttribute of the web api.
Is this a bug or do I need to use a different Filter Provider implementation hooked into the Web API?
-Tim
marcind
Contributor
3344 Points
609 Posts
Microsoft
Re: FilterAttributeFilterProvider not firing for AuthorizationFilterAttribute
Apr 07, 2012 07:06 AM|LINK
Hi,
Web API uses a completely different filter infrastructure than MVC. As a result, you will not be able to use MVC's FilterAttributeFilterProvider class to change the behavior of Web API. Instead, you will have to create a provider implementing the Web API-specific IFilterProvider interface. The provider implementation that is responsible for returning filters registered via filter attributes is the ActionDescriptorFilterProvider class.
Hope this helps.
ASP.NET Team
@marcind
Blog
.nettim
0 Points
6 Posts
Re: FilterAttributeFilterProvider not firing for AuthorizationFilterAttribute
Apr 07, 2012 02:47 PM|LINK
Marcind,
Thanks for the response. I will give this a go.
Also on another note, am I redirected to the login page when I am not authorized for an apiController? I was under the impression that the webAPI would return a 401.
btw, great job on the new api. Keep it up.
-Tim
marcind
Contributor
3344 Points
609 Posts
Microsoft
Re: FilterAttributeFilterProvider not firing for AuthorizationFilterAttribute
Apr 07, 2012 03:15 PM|LINK
That's a bug in the Web API Beta when you are hosting in an ASP.NET application. It should be fixed for the next release.
Thanks :)
ASP.NET Team
@marcind
Blog