title: How to override all standard error pages in WebAPI
body: <p>My beautiful REST webservice works great. Except if I visit pages like <code>~/</code>, which returns the default IIS 403 Forbidden page (even using Fiddler and specifying only <code>Accept: application/json</code>). I want nothing but JSON or XML errors. Is there a way to override ALL exceptions with a custom exception handler? or a default controller to handle all unknown requests? What's the simplest, and the most correct (if different), way to handle this so that clients need only parse REST API-friendly XML datagrams or JSON blobs?</p>
  
  <p>Example Request:</p>
  
  <pre><code>GET http://localhost:7414/ HTTP/1.1
  User-Agent: Fiddler
  Host: localhost:7414
  Accept: application/json, text/json, text/xml
  </code></pre>
  
  <p>Response: (that I don't like, notice that <code>text/html</code> wasn't one of the accepted response types)</p>
  
  <pre><code>HTTP/1.1 403 Forbidden
  Cache-Control: private
  Content-Type: text/html; charset=utf-8
  Server: Microsoft-IIS/8.0
  X-SourceFiles: =?UTF-8?B?QzpcaWNhcm9sXENoYXJpdHlMb2dpYy5pQ2Fyb2wuQXBp?=
  X-Powered-By: ASP.NET
  Date: Fri, 25 Jan 2013 21:06:21 GMT
  Content-Length: 5396
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; 
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; 
  &lt;head&gt; 
  &lt;title&gt;IIS 8.0 Detailed Error - 403.14 - Forbidden&lt;/title&gt; 
  &lt;style type="text/css"&gt; 
  &lt;!-- 
  ...
  </code></pre>
  
  <p>Response (that I would prefer):</p>
  
  <pre><code>HTTP/1.1 403 Forbidden
  Cache-Control: private
  Content-Type: application/json; charset=utf-8
  Date: ...
  Content-Length: ....
  
  {
    "error":"forbidden",
    "status":403,
    "error_description":"Directory listing not allowed."
  }
  </code></pre>