title: Why is my DelegatingHandler firing for MVC requests?
body: <p>I have a hybrid MVC/Web API project and I added a simple DelegatingHandler implementation to wrap the API responses. This works great, but the handler is also being invoked for requests to MVC controllers. My understanding is that DelegatingHandlers are only invoked for API routes.</p>
  
  <p>I'm using OWIN and some attribute routes if that matters. The relevant code in Startup.cs is:</p>
  
  <pre><code>var config = new HttpConfiguration();
  // ...
  var debugging = HttpContext.Current == null || HttpContext.Current.IsDebuggingEnabled;
  config.MessageHandlers.Add(new ApiResponseDelegatingHandler(debugging));
  </code></pre>
  
  <p>This causes both API and web requests to be wrapped and sent as JSON. Commenting it out resolves the problem but API requests are not wrapped. The error message on a web page is:</p>
  
  <blockquote>
    <p>No HTTP resource was found that matches the request URI 'xxx'. No
    route data was found for this request.</p>
  </blockquote>
  
  <p>I tried forcing the order that routes are registered so that MVC routes are added before Web API but that didn't help.</p>