title: throwing/returning a 404 actionresult or exception in Asp.net MVC and letting IIS handle it
body: <p>how do I throw a 404 or FileNotFound exception/result from my action and let IIS use my customErrors config section to show the 404 page?</p>
  
  <p>I've defined my customErrors like so</p>
  
  <pre><code>&lt;customErrors mode="On" defaultRedirect="/trouble"&gt;
    &lt;error statusCode="404" redirect="/notfound" /&gt;
  &lt;/customErrors&gt;
  </code></pre>
  
  <p>My first attempt at an actionResult that tries to add this doesnt work.</p>
  
  <pre><code>public class NotFoundResult : ActionResult {
      public NotFoundResult() {
  
      }
  
      public override void ExecuteResult(ControllerContext context) {
          context.HttpContext.Response.TrySkipIisCustomErrors = false;
          context.HttpContext.Response.StatusCode = 404;
      }
  }
  </code></pre>
  
  <p>But this just shows a blank page and not my /not-found page</p>
  
  <p>:(</p>
  
  <p>What should I do?</p>