I'm having an issue with exceptions showing app as stack traces in the page.
I thought that I had mitigated this by adding this to the web.config:
<customErrors mode="On" defaultRedirect="~/error/GenericError">
<error statusCode="403" redirect="~/error/NoAccess" />
<error statusCode="404" redirect="~/error/NotFound" />
</customErrors>
It works for non-existent routes, but not when a controller throws an exception.
[HandleError]
public class DebugController : Controller
{
public ActionResult Index()
{
throw new Exception("Make something go wrong to trigger custom errors");
return View();
}
}
namespace FilmFestWeb.Controllers {
public class ErrorController : Controller
{
//
// GET: /Error/
public ActionResult NotFound()
{
ViewData["error"] = "That page does not exist.";
return View();
}
public ActionResult GenericError( )
{
if (null == TempData["error"]))
{
ViewData["error"] = "We're sorry, but an error has occurred. Please contact Corporate Applications by creating a Service Now ticket or request help from your local help desk.";
}
else
{
ViewData["error"] = TempData["error"];
}
return View();
}
public ActionResult NoAccess()
{
ViewData["error"] = "You are not authorized to acccess this application. Please contact Corporate Applications by creating a Service Now ticket or request help from your local help desk.";
return View();
}
}
}
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/CenterContentNoSidebar.Master" Inherits="System.Web.Mvc.ViewPage<System.Web.Mvc.HandleErrorInfo>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> GenericError </asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>An Error has occurred</h2>
<br />
<%= ViewData["error"] %>
</asp:Content>
Do I have to put something in the Global.asax to make this work?