In my web.config, I have:
<system.web>
<customErrors mode="On" defaultRedirect="Error.cshtml" />
</system.web>
In Views/Shared/Error.cshtml, I have:
@model System.Web.Mvc.HandleErrorInfo
@{
ViewBag.Title = "Error";
}
<h2>
Sorry, an error occurred while processing your request.
</h2>
If I put an invalid URL/route into my browser, I get this:
Server Error in '/' Application.
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: /Error.cshtml
Why can't Error.cshtml be found? The file is definitely in Views/Shared.
It works for me. Just make this change in web.config:
<system.web>
<customErrors mode="On" defaultRedirect="~/Views/Shared/Error.cshtml">
</customErrors>
</system.web>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With