I want to be able to control a redirect to a different page or return a different view on certain handled errors. I can create custom pages with status 404, 403, 418, and it displays the page fine, but when I try to return 500 it overrides it with a default page. I've tried the normal solutions. Using TrySkipIisCustomErrors to get by IIS intercepting the 500 error. I have no filter.cs and register no filters in application_Start(). I've tried adding and removing [HandleError] from the method and that doesn't make a difference.
[NonAction]
[HandleError]
private ActionResult error(Exception e)
{
Response.StatusCode = 500;
Response.StatusDescription = "Internal server error: " + e.Message;
Response.TrySkipIisCustomErrors = true;
ErrorModel errorModel = new ErrorModel();
errorModel.error = e.Message;
return View(viewName: "error", model: errorModel);
}
That's the method that the error is redirected to and returns the view to be displayed. I can change the first line to other StatusCodes and it works fine, but 500 doesn't.