0

We want to set up a friendly error page for a Sitecore application. We created a new htm page in root folder and used IIS custom errors (using web.config's custom errors element) to redirect errors to that page. Its not working for some server errors. For some server errors it is not reliable at all. Sometimes it works and sometime it shows server error in '/' application. This is in IIS 8.5.

Coming to our testing environment its IIS 7.5. Here when we use custom errors of IIS (using web.config's custom errors element) it is not working at all for any server errors.

Is this the correct way. if it is, please tell us what is going wrong here. If not please suggest us the correct way. Thanks in advance :-)

As suggested by @jammykam I did try http errors method suggested in this link: How do you setup a 404 and 500 error page for missing files and media items? . This method redirects me to the error page for all 500 and 404 errors but images in the error page are not loading. Instead of images, 'x' marks are showing up. I tried the following code in web.config:

<httpErrors errorMode="DetailedLocalOnly" existingResponse="Replace">
  <remove statusCode="404" subStatusCode="-1" />
  <remove statusCode="500" subStatusCode="-1" />
  <error statusCode="404" path="C:/site_path/ErrorPage/ErrorPage.htm" responseMode="ExecuteURL" />
  <error statusCode="500" path="C:/site_path/ErrorPage/ErrorPage.htm" responseMode="File" />
</httpErrors> 

<!-- Disable for IIS 7+ -->
<customErrors mode="Off" />

where I created new error page folder in the IIS website root folder which includes ErrorPage.htm (htm web page) and image required for it. Web page loads perfectly fine when opened with any browser separately.

Not sure why the images are showing up as 'x' marks. Is it the problem with file response mode in http errors? Please help, thank you. Edit2 as per the request in comment: Html code is:

<body>
<img src="errorImage.png">
</body>

Where errorImage.png and ErrorPage.htm are in a folder named ErrorPage

I also tried the following html code:

<body>
<img src="C:/ErrorPage/errorImage.png">
</body>

which shows up only blank page without any 'x' mark.

When using the following code in web.config with AllowAbsolutePathWhenDelegated=false in iis at server level

 <httpErrors errorMode="DetailedLocalOnly" existingResponse="Replace">
  <remove statusCode="404" subStatusCode="-1" />
  <remove statusCode="500" subStatusCode="-1" />
  <error statusCode="404" path="/ErrorPage/ErrorPage.htm" responseMode="ExecuteURL" />
  <error statusCode="500" path="/ErrorPage/ErrorPage.htm" responseMode="File" />
</httpErrors> 

<!-- Disable for IIS 7+ -->
<customErrors mode="Off" />

The error page is not loading. Please help.

5
  • which version of sitecore you are using? also check this post : community.sitecore.net/developers/f/10/t/341 Mar 31, 2018 at 15:24
  • Its sitecore 8.1 Mar 31, 2018 at 18:13
  • 1
    Did you take a look at this previous question already? sitecore.stackexchange.com/q/221/135 If not, add better/more details of what you have done and examples of your configuration
    – jammykam
    Mar 31, 2018 at 20:40
  • Yes I did...I tried http errors in configuration too as given in the above link....when I tried http errors everything is working but images in the error page are not loading. Instead of images 'x' marks are showing up when I use http errors. Apr 4, 2018 at 4:55
  • Can you add code snippet of your HTML for the images. Are you relative links like ../../img/error.png or absolute path like /assets/img/error.png ?
    – jammykam
    Apr 6, 2018 at 14:06

1 Answer 1

1

You need to set the absolute path of the image in your error page, for example:

<body>
  <img src="/assets/images/errors/errorImage.png">
</body>

The reason the image works when you load the page directly in the browser is because the (I presume) the htm and image are located in the same folder, and therefore the image is correctly requested from the same folder.

If you followed the post on how to handle 404 and 500 errors then you will note that when the error is thrown, the URL remains the same as what the user requested (rather than it redirecting users to the 404 page). The image shows up with an 'x' because it was not found, because it is looking for the image in the same folder as the request URL (which will not be the ErrorPage folder). Setting the absolute path to the image (and any other assets on the page) will mean they resolve correctly regardless if the request URL.

4
  • I tried with absolute path also when relative path didn't work on the first time itself. This one doesn't even show the 'x' mark. It simply shows a blank page if page has only image. If page has some text then it shows up only the text and image is blank. Apr 10, 2018 at 7:25
  • I would use the developer tools in the browser and check the network tab, most likely you are getting a 404 for the image, you need to resolve the path.
    – jammykam
    Apr 10, 2018 at 13:11
  • Yeah it is the problem with image path. Thanks for the suggestions. Apr 13, 2018 at 9:35
  • Hi jammy, This is working fine when response mode is file and the file's absolute path is provided. But when AllowAbsolutePathWhenDelegated=false, responsemode is file and file's relative path is provided the error page is not loading. It says server error 500. Tried developer options but it is showing nothing. Please help Apr 20, 2018 at 5:02

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