4

For handling status code 500 followed below step in web.config file:

<system.web>
    <customErrors mode="off" />
<system.web>

</system.webServer>
    <httpErrors errorMode="Custom">
        <remove statusCode="500" />
        <error statusCode="500" path="/sitecore/service/500.aspx" responseMode="ExecuteURL" />
    </httpErrors>
</system.webServer>

In case if I add this part instead of httpErrors getting an internal error

<system.web>
   <customErrors mode="RemoteOnly" defaultRedirect="/sitecore/service/500.aspx"/>
</system.web>

error

       The page cannot be displayed because an internal server error has 
         occurred on server

500.aspx:

      <%
Response.StatusCode = 500;
Response.TrySkipIisCustomErrors = true;
     %>
    <!doctype html>
   <html lang="en">
     <head>
<title>An Error Occurred</title>
  </head>
   <body>
<h1>An Error Occurred</h1>
<h4>Our server couldn't complete your request.
    <br />
    Please refresh your browser and try again soon.
</h4>
<a href="/">Home</a>
<p>
    Error Code: 500
</p>
</body>
</html>

please advice better approach to handling this scenario.

  • Little unclear if you get the error only when you add the second section? Also, what's on the logs? That should tell you what went wrong, Is there an exception on your error page? – Jarmo Jarvi Aug 22 '18 at 17:06
  • @jammykam I followed the above-mentioned URL so many steps very confusing .below mentioned approach is very simple and straightforward. – sindu Aug 22 '18 at 19:39
6

The error handling for Sitecore 9 is the same as Sitecore 8.x

For me, I like to have my error pages as html pages so that it wont cause a loop if I have a serious issue. Here I remove all the existing code and add my new ones to my custom html files.

Web.config

<system.webServer>
    <httpErrors errorMode="Custom" existingResponse="Auto">
        <remove statusCode="403" />
        <remove statusCode="404" />
        <remove statusCode="500" />
        <error statusCode="500" responseMode="Redirect" path="/500.html" />
        <error statusCode="403" responseMode="Redirect" path="/404.html" />
        <error statusCode="404" responseMode="Redirect" path="/404.html" />
    </httpErrors>
</system.webServer>

I do the same thing in my custom errors. This might be overkill, but lets cover our bases.

<system.web>
    <customErrors mode="On" defaultRedirect="500.html" redirectMode="ResponseRewrite">
        <error statusCode="403" redirect="/404.html" />
        <error statusCode="404" redirect="/404.html" />
        <error statusCode="500" redirect="/500.html" />
    </customErrors>
</system.web>

Sitecore

And in Sitecore set the Layout Not Found and Item Not Found urls

<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <settings>
      <setting name="LayoutNotFoundUrl">
        <patch:attribute name="value">/404.html</patch:attribute>
      </setting>
      <setting name="ItemNotFoundUrl">
        <patch:attribute name="value">/404.html</patch:attribute>
      </setting>
    </settings>
  </sitecore>
</configuration>

MVC

And to go to the next level, you can track your MVC exceptions in a pipeline.

namespace Customer.Foundation.Logging.Pipelines
{
    using System.Web;
    using System.Web.Configuration;
    using Sitecore.Mvc.Pipelines.MvcEvents.Exception;
    using Sitecore.Diagnostics;
    using Sitecore.Configuration;
    using Customer.Foundation.Logging.Services;

    public class GenericExceptionHandler : ExceptionProcessor
    {
        public override void Process(ExceptionArgs args)
        {
            Log.Error("MVC generic exception processing " + Sitecore.Context.RawUrl, args.ExceptionContext.Exception, this);
            CustomErrorsMode mode = Settings.CustomErrorsMode;

            if (mode == CustomErrorsMode.Off
                // to show details to Sitecore admins: || SC.Context.User.IsAdministrator 
                // to show in the Page Editor: || SC.Context.PageMode.IsPageEditor
                // to show in Preview: || SC.Context.PageMode.IsPreview
                // to show in the debugger: || SC.Context.PageMode.IsDebugging
                || (mode == CustomErrorsMode.RemoteOnly && HttpContext.Current.Request.IsLocal))
            {
                return;
            }

            // THIS IS A CUSTOMER ERROR ALERTING SERVICE LIKE Sentry.io 
            ErrorService errorService = new ErrorService();
            errorService.SendErrorToService(args.ExceptionContext.Exception);

            Sitecore.Web.WebUtil.RedirectToErrorPage("An error has occurred");
            args.ExceptionContext.ExceptionHandled = true;
        }
    }
}

An that is brought together with a patch config.

<sitecore>
    <pipelines>
        <mvc.renderRendering>
            <processor type="Sitecore.Mvc.Pipelines.Response.RenderRendering.ExecuteRenderer, Sitecore.Mvc">
                <patch:attribute name="type">Customer.Foundation.Logging.Pipelines.ExecuteRenderer, Customer.Foundation.Logging</patch:attribute>
            </processor>
        </mvc.renderRendering>
    </pipelines>        
</sitecore>
| improve this answer | |
  • when I try the ExceptionProcessor I get a error "Sitecore.Exception.Handler.Pipelines.Response.RenderRendering.RenderRendering.ExecuteRenderer" No matching constructor was found." do you know this problem? – squadwuschel Aug 8 '19 at 8:54
  • @squadwuschel Yes, you must include some constructors. Something like public ExecuteRenderer() { } and public ExecuteRenderer(Rendering.IRendererErrorStrategy errorStrategy) :base(errorStrategy) { } – Marcel Jun 5 at 17:43

Not the answer you're looking for? Browse other questions tagged or ask your own question.