I am trying to configure the Magical Unicorn Mvc Error Toolkit (v 2.1.2) on my MVC4 web site but I can't get it to work. Here's my code:
Web.config
<customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="~/Error/ServerError">
<error statusCode="404" redirect="~/Views/Error/NotFound.cshtml" />
</customErrors>
<system.webServer>
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404" subStatusCode="-1" />
<remove statusCode="500" subStatusCode="-1" />
<error statusCode="404" path="~/Error/NotFound" responseMode="ExecuteURL" />
<error statusCode="500" path="~/Error/ServerError" responseMode="ExecuteURL" />
</httpErrors>
<system.webServer>
Error Controller
public class ErrorController : Controller
{
public ActionResult NotFound()
{
Response.StatusCode = (int)HttpStatusCode.NotFound;
return View();
}
public ActionResult ServerError()
{
Response.StatusCode = (int)HttpStatusCode.InternalServerError;
return View();
}
}
[These were based on this https://stackoverflow.com/a/7499406/236860 post]
CustomerErrorHandler.cs (App_Start)
using Microsoft.Web.Infrastructure.DynamicModuleHelper;
using WorldDomination.Web.Mvc;
using CustomErrors.App_Start;
[assembly: WebActivator.PreApplicationStartMethod(typeof(CustomErrorHander), "PreStart")]
namespace CustomErrors.App_Start
{
public static class CustomErrorHander
{
public static void PreStart()
{
// Register the custom error handling module.
DynamicModuleUtility.RegisterModule(typeof (CustomErrorHandlingModule));
}
}
}
I am testing this application in Visual Studio 2012 using IIS Express. If I try to navigate to a non-existent page, or go to an action method that calls an exception I either get the default browser error page or a blank page.
I have also modified the above code as suggested at ASP.NET MVC Custom Error Pages with Magical Unicorn but this dis not seem to make any difference.
Can anyone point me in the right direction to get this working.