title: Is there a simple way to replace the ASP.NET Web API HTML error page with a simple Error.json file?
body: <p>I feel like I may be over complicating things with a guide like this one:
  <a href="https://stackoverflow.com/questions/14530387/how-to-override-all-standard-error-pages-in-webapi">How to override all standard error pages in WebAPI</a></p>
  
  <p>I couldn't get it to work because I think the version of ASP.NET Web API that I'm using has deprecated the <code>context.Request.CreateErrorInfoResponse()</code></p>
  
  <p>All I want to do is display an HTTP 403 Forbidden as a single static file located in <code>~/Error.json</code></p>
  
  <p>I've tried doing this to my Web.config file:</p>
  
  <pre><code>  &lt;system.web&gt;
      &lt;customErrors mode="RemoteOnly"&gt;
        &lt;error statusCode="403" redirect="~/Error.json" /&gt;
      &lt;/customErrors&gt;
    &lt;/system.web&gt;
  </code></pre>
  
  <p>And I've tried this too:</p>
  
  <pre><code>  &lt;system.web&gt;
      &lt;customErrors mode="On"&gt;
        &lt;error statusCode="403" redirect="~/Error.json" /&gt;
      &lt;/customErrors&gt;
    &lt;/system.web&gt;
  </code></pre>
  
  <p>It doesn't seem to have any effect at all when this exception is thrown:</p>
  
  <pre><code>throw new APIException(HttpStatusCode.Forbidden, new MessageError("foobar"));
  </code></pre>
  
  <p>In my application, there will be only one situation where a Forbidden response is received, and I don't want my RESTful API to be returning an HTML response in this event.</p>
  
  <p>What can I do to fix this?</p>
  
  <p>The reason why I need to do this is to render the Web Application useless if a customer tries to crack or pirate this web application. I would like to do all of this within Startup.cs if it's possible to crash the app and to return a json response of the error rather than an HTML response that the <code>throw new Exception</code> method does by default.</p>