Background: In a public ASP.NET MVC4 application, sometimes I get incoming requests to a bad URL. The referrer is from outside, so my application is out of my control (I am not creating a bad URL in my application). In this way, MVC correctly throws an exception and the user sees the user error page. Global .ax is encoded for email errors for me.
Problem. Although the url is bad, the error I get is unexpected.
Example: - The user translates (from an external URL) to / Blog / View - The blog controller does not have the "View" action - the user is presented with a web page with the error Error500 - The error I receive by email:
The view "Error" or its wizard is not found or there is no viewing mechanism that supports the found locations. The following places were searched: ~ / Views / Blog / Error .aspx ~ / Views / Blog / Error .ascx ~ / Views / Shared / Error.aspx ~ / Views / Shared / Error.ascx ~ / Views / Blog / Error .cshtml ~ / Views / Blog / Error .vbhtml ~ / Views / Shared / Error.cshtml ~ / Views / Shared / Error.vbhtml
I do not understand why ASP.NET MVC4 is looking for a view named "Error", and why MVC is not looking for the view as indicated (Error500) in web.config. Here are the applicable source files:
Web.Config:
<customErrors mode="RemoteOnly" defaultRedirect="~/Error/Error500">
<error statusCode="404" redirect="~/Error/Error404" />
</customErrors>
ErrorController File:
public class ErrorController : Controller
{
public ActionResult Error500()
{
return View();
}
public ActionResult Error404()
{
return View();
}
}
File Error404.cshtml (located in the / Views / Error folder):
@{
ViewBag.Title = "Oops...";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h1>That interesting</h1>
<p>The page you were looking for could not be found.</p>
File Error500.cshtml (located in the / Views / Error folder):
@{
ViewBag.Title = "Oops...";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h1>We're sorry about that</h1>
<p>Something unexpected just happened. Our IT staff has been notified...time to code a hot-fix!</p>
source
share