So, I wanted to apply some friendly error pages to an existing app; due to some recent Azure issues revealing the standard .NET "yellow page of death" too many times. I used this example: Displaying custom error CSHTML page in MVC5 on 404 / 500 / any exception?
Everything seems to work okay (in respect of the error code picking up the correct view), but the resulting response is the full HTML as text. The page isn't rendering... This appears to be for Chrome, Edge works fine. I'm assuming it isn't a browser specific issue, but something I've inadvertantly introduced.
Any ideas how I can force this page to render? Am I missing a specific 'redirect' action rather than a "ReWrite"; I've already checked redirectMode="ResponseRedirect".
Web.config:
<system.web>
<authentication mode="None" />
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
<customErrors mode="On" defaultRedirect="~/Error" redirectMode="ResponseRedirect">
<error redirect="~/Error/HttpError404" statusCode="404"/>
<error redirect="~/Error/HttpError500" statusCode="500"/>
</customErrors>
</system.web>
ErrorController:
namespace RMS.Web.Controllers.Web
{
using System.Web.Mvc;
public class ErrorController : Controller
{
public ActionResult Error()
{
return View();
}
public ActionResult HttpError404()
{
Response.StatusCode = 200;
return View();
}
public ActionResult HttpError500()
{
Response.StatusCode = 200;
return View();
}
}
}
Standard View (Each view is a slight variation on these)
@model System.Web.Mvc.HandleErrorInfo
@{
ViewBag.Title = "Error";
}
<div class="error">
<div class="error-code m-b-10 m-t-20">Error 404<i class="fa fa-warning"></i></div>
<h3 class="font-bold">We couldn't find the page..</h3>
<div class="error-desc">
Sorry, but the page you are looking for was either not found or does not exist. <br />
Try refreshing the page or click the button below to go back to the Homepage.
<div>
<a class="login-detail-panel-button btn" href="/Home/Index">
<i class="fa fa-arrow-left"></i>
Go back to Homepage
</a>
</div>
<div>
@*@Model.Exception*@
</div>
</div>
</div>