Last post Apr 21, 2016 06:04 PM by Jamie Ide
Apr 15, 2016 07:58 PM|Jamie Ide|LINK
Adding a DelagatingHandler implementation in an OWIN Startup class causes the handler to be invoked for both MVC and Web API route requests. My understanding is that DelegatingHandlers should only be invoked for routes to controllers that extend ApiController.
It's easy to reproduce
If I add the DelegatingHandler in WebApiConfig it behaves as expected. Is this a bug?
Apr 18, 2016 07:09 AM|Yohann Lu|LINK
Hi Jamie Ide,
As far as I know, If you use OWIN, it could be possible to use Web API DelegatingHandler in MVC but this is still in beta. So, It maybe has some problems.
I suggest you can refer the following links and use the stable technology.
1: HTTP Message Handlers in ASP.NET Web API:
2: Why does a call to an ASP.NET MVC Controller not execute a DelegatingHandler:
Apr 21, 2016 06:04 PM|Jamie Ide|LINK
Thanks for your reply. I don't think I'm using anything that is in beta and a DelgatingHandler is a message handler.
I tried several combinations of startup code before I found a workaround. In the handler, I am checking if the route starts with "/api/" and only wrapping the response if it does.
public class WtfDelegatingHandler : DelegatingHandler
protected async override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
var response = await base.SendAsync(request, cancellationToken);
if (request.RequestUri.LocalPath.StartsWith("/api/", StringComparison.OrdinalIgnoreCase))
response = new HttpResponseMessage()
StatusCode = HttpStatusCode.OK,
Content = new StringContent("hello world!")