Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I was never able to get CustomErrors in a web.config and MVC to play nice together, so I gave up. I do this instead.</p> <p>In global.asax:</p> <pre><code>protected void Application_Error() { var exception = Server.GetLastError(); var httpException = exception as HttpException; Response.Clear(); Server.ClearError(); var routeData = new RouteData(); routeData.Values["controller"] = "Errors"; routeData.Values["action"] = "General"; routeData.Values["exception"] = exception; Response.StatusCode = 500; if (httpException != null) { Response.StatusCode = httpException.GetHttpCode(); switch (Response.StatusCode) { case 403: routeData.Values["action"] = "Http403"; break; case 404: routeData.Values["action"] = "Http404"; break; } } // Avoid IIS7 getting in the middle Response.TrySkipIisCustomErrors = true; IController errorsController = new GNB.LG.StrategicPlanning.Website.Controllers.ErrorsController(); HttpContextWrapper wrapper = new HttpContextWrapper(Context); var rc = new RequestContext(wrapper, routeData); errorsController.Execute(rc); } </code></pre> <p>In ErrorsController:</p> <pre><code>public class ErrorsController { public ActionResult General(Exception exception) { // log the error here return View(exception); } public ActionResult Http404() { return View("404"); } public ActionResult Http403() { return View("403"); } } </code></pre> <p>In web.config:</p> <pre><code>&lt;customErrors mode="Off" /&gt; </code></pre> <p>That's worked for me no matter where or how the error is created. 401 isn't handled there right now but you could add it pretty easily.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload