I triedd all possible ways I found either here (How to make custom error pages work in ASP.NET MVC 4) or here: http://benfoster.io/blog/aspnet-mvc-custom-error-pages, here: http://www.secretgeek.net/custom_errors_mvc but none seems to be working for me.
I simplified it to the minium, but still geting ugly standard error message when hitting page that does not exist.
My Error.cshtml is placed in Views\Shared folder and it looks like:
<div>
<span>Error occurred</span>
</div>
tried also:
@model System.Web.Mvc.HandleErrorInfo
@{
ViewBag.Title = "Parking & Ticket Scan Information - Error";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div>
<span>Error occurred</span>
</div>
My web.config contains:
<customErrors mode="On" defaultRedirect="~/Error">
<error redirect="~/Error/NotFound" statusCode="404" />
</customErrors>
but I tried also:
<customErrors mode="On" defaultRedirect="~/Error">
</customErrors>
My ErrorController is like:
public class ErrorController : Controller
{
[HandleError]
public ViewResult Index()
{
return View();
}
}
(with or without [HandleError] attribute, with and without
public ViewResult NotFound()
{
Response.StatusCode = 404; //you may want to set this to 200
return View("NotFound");
}
Later I added also routing in Global.asax:
routes.MapRoute( name: "PageNotFound", url: "{*url}", defaults: new { controller = "Error", action = "Index", id = UrlParameter.Optional }
Nothing seems to force IIS to show custom error. What else did I try? Of course commented out filters.Add(new HandleErrorAttribute()); Moved Error.cshtml to Views folder.
Are there any other approaches I could use to enable it?