title: Why does Response.StatusCode = (int)HttpStatusCode.NotFound give me the generic error handler?
body: <p>I catch and redirect 404 errors to an Error controller \ views with the following code. </p>
  
  <pre><code>Response.Clear();
  Server.ClearError();
  var routeData = new RouteData();
  routeData.Values["controller"] = "Error";
  routeData.Values["action"] = "HttpError";
  routeData.Values["exception"] = exception;          
  
  Response.StatusCode = 500;
  //if http 404 redirect to http404 action
  if (httpException != null)
  {
      Response.StatusCode = httpException.GetHttpCode();
      switch (Response.StatusCode)
      {
          case 404:
              routeData.Values["action"] = "Http404";
              break;
      }
  }
  </code></pre>
  
  <p>In the error controller if I set Response.StatusCode = (int)HttpStatusCode.NotFound I get the generic error handler, not the view I returned.  This only seems to happen in production. Any ideas why?</p>
  
  <pre><code>[AllowAnonymous]
  public ActionResult Http404()
  {
      //this line causes generic error handler
      Response.StatusCode = (int)HttpStatusCode.NotFound;
  
      var viewModel = new ErrorViewModel
      {
          Description = "Hmm, the page you're looking for can't be found"
      };
  
      return View("Error", viewModel);
  }
  </code></pre>