Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jim 7 posts 27 karma points
    Jun 01, 2015 @ 16:26
    Jim
    0

    How to set up a Custom Error page for 500 Errors

    I just want a custom error page when a server error occurs - I've tried endless combinations of suggestions that I've found on google but nothing even begins to get me there.

    Essentially, I have some error handling routines in my surface controllers where I want to log the error & then throw the exception so that somewhere down the line a 500 response code is returned & a custom error page is displayed.

    e.g.

                       try { repository.AddShoppingCartItem(sci); } catch(Exception e) { Log.Error("whatever..."); throw; }

    The surface controller methods are invoked from macros via @Html.Action.  When I force the exception I can see in Chrome tools network profiler that a 200 reponse comes back.  That's weird because in a normal MVC app I would expect to see a response of 500 at that point.

    I'm not sure whther I'm supposed to be doing this in the context of Umbraco or treating it as a pure MVC issue - In a normal MVC app I would create a controller called ErrorController & have its Index method return the view containing my error page mark up.

    Do I take this approach in Umbraco?  Or do I need to do all this via a surface controller?

     

    I have tried both these approaches & neither work -  in my web.config I've tried:

     

     

     

     

     

    <customErrors mode="On" defaultRedirect="error"> </customErrors>

    and

     

     <customErrors mode="On" defaultRedirect="umbraco/surface/errorsurface"> </customErrors> 

    Neither work.  I can force the server by retuning a response code of 500 from my exception ahndler but all I get then is a nasty IIS error.

     

    Anyone got any pointers on how to achieve this in Umbraco 7?

     

  • Chris Wilson 100 posts 377 karma points
    Jun 01, 2015 @ 17:18
    Chris Wilson
    0

    In umbracoSettings.config, have you set the trySkipIisCustomErrors attribute on web.routing to "true"?

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jun 01, 2015 @ 18:50
    Dennis Aaen
    1

    Hi Jim and welcome to our :-),

    If you want to setup a custom Error page for 500 errors. Then the first step is to make a html page, and put it in root of your site.

    After this you will need to add defaultRedirect attribute to the customErrors tag in the web.config file, and point to the html file that you just have created.

    <customErrors mode="RemoteOnly" defaultRedirect="~/500.html" />
    

    Hope this helps,

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft