title: Web API - How to Prevent 404 HTML Response?
body: <p>How can I change ASP.NET Web API to never return a <code>text/html</code> 404 response? I'd rather it send back XML/JSON with an <code>ExceptionMessage</code> or <code>Message</code>. It doesn't make sense to return HTML from an API, IMO.</p>
  
  <p>Just to clarify, this is for cases when the URL truly is invalid.</p>
  
  <p>Another problem is that I am hosting MVC and Web API in the same project, so I need to respond differently. I am guessing it will depend on whether the URL starts with "api".</p>