I may have found a bug in ASP.NET WebAPI but I'm hoping that I'm just "doing it wrong." My scenario is that I've created a DelegatingHandler to look for the Authorization header, verify the value, and return the appropriate response code should it not be
present or verification failed.
The problem however is that I don't want this message handler to run for all routes and therefore I have it configured for my DefaultApi route like so:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional },
constraints: null,
handler: newAuthorizationMessageHandler()
);
When adding the handler via DefaultApi route I recieve the error: "The inner handler has not been assigned." I don't receive this error when the handler is configured globally.
This will fail with even the most basic DelegatingHandler:
rgraham
Member
2 Points
4 Posts
The inner handler has not been assigned.
Dec 19, 2012 06:41 AM|LINK
Hi Everyone,
I may have found a bug in ASP.NET WebAPI but I'm hoping that I'm just "doing it wrong." My scenario is that I've created a DelegatingHandler to look for the Authorization header, verify the value, and return the appropriate response code should it not be present or verification failed.
The problem however is that I don't want this message handler to run for all routes and therefore I have it configured for my DefaultApi route like so:
config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional }, constraints: null, handler: new AuthorizationMessageHandler() );rather than globally:
When adding the handler via DefaultApi route I recieve the error: "The inner handler has not been assigned." I don't receive this error when the handler is configured globally.
This will fail with even the most basic DelegatingHandler:
Having said that, am I doing something wrong or does this look to be a bug in WebAPI?
Thanks in advance for your help!
Ryan
dbaier
Member
264 Points
66 Posts
MVP
Re: The inner handler has not been assigned.
Dec 19, 2012 07:46 AM|LINK
You need to set the InnerHandler on per-route handlers.
See here:
https://github.com/thinktecture/Thinktecture.IdentityModel.45/blob/master/IdentityModel/Thinktecture.IdentityModel/Tokens/Http/AuthenticationHandler.cs
dominick
_____________________________
Dominick Baier - http://www.leastprivilege.com
rgraham
Member
2 Points
4 Posts
Re: The inner handler has not been assigned.
Dec 20, 2012 05:16 AM|LINK
Thanks Dominick - that's exactly what I needed!
Ryan