500 Error Page in your Sitecore application

I have been asked about the simplest implementation of a 500 Error Page for a Sitecore project that support Multiple Sites/Brands and multiple languages….

There are several theories on how to implement it, but in my opinion the 500 Error page HAS to be a static Html file…
Therefore I would recommend the following implementation within your Global.Asax

private void Application_Error( object sender, EventArgs e)
 {
    var customErrorsSection = ( CustomErrorsSection)   ConfigurationManager.GetSection("system.web/customErrors" );
    var lastException = Server.GetLastError();
    if (customErrorsSection.Mode != CustomErrorsMode.Off)
       {
         try
             {
               Log.Error( "There was an error in the application", lastException);
               Server.ClearError();
    HttpContext.Current.Response.StatusCode = (int )HttpStatusCode.InternalServerError;
      Server.Transfer( string.Format( "/Error/{0}_500.html" , GetSafeLanguage()));
                }
                catch
                 {
                 }
         }
 }

private string GetSafeLanguage()
 {
    try
        {
          return Sitecore.Context.Language.CultureInfo.TwoLetterISOLanguageName;
        }
        catch
        {
        }
          return string.Empty;
 }

I would also recommend the following setting to handle Sitecore Pipelines error as all normal errors

<system.webServer>
 <httpErrors existingResponse="PassThrough" />

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s