I have a standard ASP.NET MVC application. Here I want to redirect all errors to a custom error page.
I have tried to set this up based on what I usually do + can Google, but still, I don't get the error.
I have the following web.config:
<system.web>
<customErrors mode="On" defaultRedirect="~/Error/Index">
<error redirect="~/Error/NotFound" statusCode="404" />
<error redirect="~/Error/Index" statusCode="500" />
</customErrors>
<!-- More stuff :-) -->
</system.web>
<system.webServer>
This is my error controller:
public class ErrorController : Controller
{
public ViewResult Index()
{
return View("Error");
}
public ViewResult NotFound()
{
Response.StatusCode = 404;
return View("NotFound");
}
}
I have the following FilterConfig
:
public class FilterConfig
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
}
However, when I create an error in my Index Controller:
public ActionResult Index(InvoiceOverviewViewModel vm)
{
// used to test error pages :D
int a = 5;
int b = 0;
int res = a / b;
}
Which gives an error, I see the following:
While my Index.cshtml
inside the ErrorController
has the following view:
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_VerifyLayout.cshtml";
}
<h1>Danish text that doesn't make any sense here ;-) </h1>
What makes it even a bit more weird, is that my 404 page works. This page renders perfectly on localhost (not on production, however).
Any ideas?