12

I've got this in the web.config:

<httpErrors errorMode="Custom">
  <remove statusCode="404" subStatusCode="-1" />
  <remove statusCode="500" subStatusCode="-1" />
  <error statusCode="404" prefixLanguageFilePath="" path="/Error/NotFound.aspx" responseMode="Redirect" />
  <error statusCode="500" prefixLanguageFilePath="" path="/Error/ServerError.aspx" responseMode="Redirect" />
</httpErrors>

But IIS still shows the built in error page.

Any ideas?

oekstrem
  • 477
  • 3
  • 6
  • 12

5 Answers5

20

You may also need to set the existingReponse attribute in the httpErrors element like this:

<httpErrors errorMode="Custom" existingResponse="Replace">
  <clear />
      <error statusCode="404" prefixLanguageFilePath="" path="/ErrorHandler.aspx" responseMode="ExecuteURL" />
  <error statusCode="500" prefixLanguageFilePath="" path="/ErrorHandler.aspx" responseMode="ExecuteURL" />
</httpErrors>
michael_hook
  • 1,936
  • 14
  • 10
  • This is what was causing issue with the latest Orchard 1.4, cheers. – Sarkie May 03 '12 at 13:43
  • @Kiquenet http://www.iis.net/configreference/system.webserver/httperrors Not sure but Auto solved my issue. – Ernesto Jun 08 '16 at 22:44
  • Beware that using `existingResponse="Replace"` will replace all returns. For example, if you call a webapi that sends a return with statuscode=404 this will override the answer, use `existingResponse="PassThrough"` so that an explicit answer gets through. – Rui Caramalho Feb 19 '21 at 19:12
6

This is how I am using it and it works to me, it looks pretty similar except for the subStatusCode directives and the ExecuteURL.


<httpErrors>
     <!--Remove inherited 500 error page setting -->
     <remove statusCode='500' subStatusCode='-1'/> 
     <!--Override the inherited 500 error page setting with the 'My500.html' as its path-->
     <error statusCode='500' subStatusCode='-1' prefixLanguageFilePath='' path='/My500.html' responseMode='ExecuteURL'/> 
</httpErrors>
Freddy
  • 3,064
  • 3
  • 26
  • 27
5

If you are using ExecuteURL, the custom error page path must be in the same application pool as the application itself.

For architectural reasons, IIS 7.0 can only execute the URL if it is located in the same Application Pool. Use the redirect feature to execute a Custom Error in a different Application Pool.

favo
  • 69
  • 1
  • 2
2

It seems as though you are using a server relative URL, try setting responseMode="ExecuteURL", from MSDN.

ExecuteURL

Serves dynamic content (for example, an .asp file) specified in the path attribute for the custom error. If responseMode is set to ExecuteURL, the path value has to be a server relative URL. The numeric value is 1.

Redirect

Redirects client browsers to a the URL specified in the path attribute that contains the custom error file. If responseMode is set to Redirect, the path value has to be an absolute URL. The numeric value is 2.

Phaedrus
  • 8,351
  • 26
  • 28
0

Ensure that you have the proper feature setting for the Error Page redirection in IIS. To check this, from the Error Pages page in IIS Manager, click Edit Feature Settings and make sure Custom error pages is checked if you are testing the redirects from the web server itself. If you are testing remotely, you can leave Detailed errors for local requests and custom error pages for remote requests is checked. This appears to be the default option in my test environment.

JPC
  • 412
  • 4
  • 6