SC9.1 but tested in 8.2 also.

I have been using my tried and true httpError config for capturing 500 errors to a static file. I was setting it up for a new client and I thought changing the connection string would be a good test. But once I did, I got a hard server error below. By change I mean I changed the web database connection string to webXX.

Server Error in '/' Application. Runtime Error Description: An exception occurred while processing your request. Additionally, another exception occurred while executing the custom error page for the first exception. The request has been terminated.

I updated the IgnoreUrlPrefixes with my 500.html page and the httpsErrors section below. I can't even render an html page, jpg, nothing with a broken connection string.

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

<customErrors mode="On" defaultRedirect="500.htm" >
  <error statusCode="500" redirect="500.html" />
  <error statusCode="404" redirect="500.html" />

It appears with Sitecore there are things you can do that completely shutdown IIS.

Any way around this? If IIS can't even render a 500 page, there isn't much hope of redirecting a 500 page on error.

3 Answers 3


In this special case the only option would be to have the 500.html page outside your webroot, otherwise you'll get an error when the site tries to load the page due to configuration error. In order to move it outside the webroot you have to specify it with absolute path like this:

<httpErrors errorMode="Custom" existingResponse="Replace">
    <remove statusCode="500"/>
    <error statusCode="500" responseMode="File" path="c:\inetpub\wwwroot\500.html"/>

with a 404 redirect

<httpErrors errorMode="Custom" defaultResponseMode="File" existingResponse="Replace"> 
    <remove statusCode="404" />
    <remove statusCode="500" /> 
    <error statusCode="404" responseMode="ExecuteURL" path="/404" />
    <error statusCode="500" path="500.html" /> 

If you get the error absolute path is not allowed is not allowed in system.webServer/httpErrors you have to set allowAbsolutePathsWhenDelegated to true in IIS > Configuration Editor > in Section type: system.webServer/httpErrors. Also you'll have to remove the custom redirect from the customErrors section.

  • This works like a charm. My issue initially was that I had /500.html and it needed to but 500.html with no leading "/". I can break any config and it still renders the 500 html page. I added a 404 redirect because I needed to solve that with this.
    – Chris Auer
    Commented Feb 27, 2021 at 0:48

The custom errors is making it hard to see what the actual issue is. When turning off custom errors you would see something like this (truncated to show relevant info only):

   Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain) +22
   Sitecore.Nexus.Web.HttpModule.Application_Start() +161
   Sitecore.Nexus.Web.HttpModule.Init(HttpApplication app) +767
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +573
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +168
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +277
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +369

As can be seen this error comes from the Application_Start in the Sitecore.Nexus.Web.HttpModule The application start event is not associated with a specific request and therefore a redirect cannot happen from it. Fixing this will be hard as the Sitecore.Nexus DLL cannot be changed and validates the Sitecore license among other things. Not sure if this is worth it but an approach like this might work:

  1. Override the code which reads the connection strings and do not throw an error, but set some flag instead when there is an issue reading the connection string
  2. Ensure no other errors occur and the Application_Start completes without unhandled errors
  3. In Application_BeginRequest read the flag from step 1 and throw an error so the custom error handler can respond to it

You're running into the issue of runAllManagedModulesForAllRequests being "true" in Sitecore. I solved this in the past but don't have the answer handy right now sadly. Though I can refer you to an SO thread that will most likely hold the keys to solving this issue: https://stackoverflow.com/questions/40151520/customerrors-vs-custom-modules

  • this did not work, it never hits Application_Error method for the above scenario Commented Feb 26, 2021 at 4:49
  • 1
    And you replaced the Global.asax with your own? I might have some time today to have a deeper look.
    – IvanL
    Commented Feb 26, 2021 at 8:56
  • I did a few quick tests on a clean 9.3 and I could have the custom file show up instead of YSOD on connectionstring error relatively quickly using: <system.webServer> <httpErrors errorMode="Custom" defaultResponseMode="File" existingResponse="Replace"> <remove statusCode="500" /> <error statusCode="500" path="500.htm" /> </httpErrors> </system.webServer>
    – IvanL
    Commented Feb 26, 2021 at 9:13
  • Key thing is the existingResponse="Replace" because your YSOD is an actual response, but not one you want.
    – IvanL
    Commented Feb 26, 2021 at 9:15
  • Yes, I replaced global.asax with my own Commented Feb 26, 2021 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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