Reputation: 12915
I'm trying to follow the answer to this question:
How to make custom error pages work in ASP.NET MVC 4
I have the following in my Web.Release.config:
<system.web>
<customErrors mode="On" defaultRedirect="~/Error">
<error redirect="~/Error/NotFound" statusCode="404" />
</customErrors>
</system.web>
I'm running in Release mode. I've added the following controller:
public class ErrorController : Controller
{
public ViewResult Index()
{
return View("Error");
}
public ViewResult NotFound()
{
Response.StatusCode = 404; //you may want to set this to 200
return View("NotFound");
}
}
And views for the controller actions:
@model System.Web.Mvc.HandleErrorInfo
@{
Layout = "../Shared/_Layout.cshtml";
ViewBag.Title = "Error";
}
<div class="list-header clearfix">
<span>Error</span>
</div>
<div class="list-sfs-holder">
<div class="alert alert-error">
An unexpected error has occurred.
</div>
</div>
I can access these pages via manual navigation. If I navigate to some bogus URL though, I get the standard yellow error page with ugly diagnostics info.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /ss
What am I doing wrong?
Upvotes: 2
Views: 3379
Reputation: 3479
If custom errors are enabled, as in your example, and you are using the HandleErrorAttribute
, the ASP.NET MVC runtime looks for the Error.chtml
file in the current requests folder or in the shared
views folder. In this setup, the defaultRedirect (to GenericErrorPage.htm)
and status
code redirect URI ("~/Error/NotFound") are ignored.
Upvotes: 2