Quickly get custom/friendly error pages configured in Sitecore.
Version 1.x verified on Sitecore 8.x - 9.2. Version 2.x verified on Sitecore 9.x+. In other words only 2.x will work for 9.3+.
Use at your own risk. While all changes are documented and available here (and this technique is used on multiple websites in production), these updates replace two pieces of existing Sitecore functionality:
<processor type="Sitecore.Pipelines.HttpRequest.ExecuteRequest, Sitecore.Kernel"/>
<add verb="*" path="sitecore_media.ashx" type="Sitecore.Resources.Media.MediaRequestHandler, Sitecore.Kernel" name="Sitecore.MediaRequestHandler" />
The two replacement classes inherit the originals. These pieces are intentionally replaced to alter how the RequestErrors.UseServerSideRedirect
setting is interpretted. By default, when true, Sitecore runs Server.Transfer
on the given URL. Server.Transfer
does not re-execute the request, instead it sends the user directly to a page, which is why the default ItemNotFoundUrl
is a physical page on the server, it bypasses all pipelines associated with the request. The code in this repository changes this to use Server.TransferRequest
, which sends the request behind the scenes and re-executes the request with all pipelines. This allows us to pass a Sitecore website path as the 404 page.
- Install the NuGet Package in your Sitecore web project: https://www.nuget.org/packages/Sitecore.FriendlyErrors
- Build and publish web project to web root
- Add an item named "404" beneath all websites ex: /sitecore/content/home/404 Be sure this item has a layout defined in Presentation Details
- Verify friendly 404 page is returned by visiting an incorrect link on your website
- Review Next Steps below
If working properly, your URL should remain as entered, however the response from the server should be a 404. You can verify with Fiddler or Inspect Element > Network traffic in Chrome.
By default, all error modes are set to RemoteOnly (or the equivalent). These are the proper settings for a production environment. To test the static 404 and 500 pages make the following changes to the web.config:
<configuration> <system.web> <customErrors mode="On"...
<configuration> <system.webServer> <httpErrors errorMode="Custom"...
With these changes in place, you can test the static 404 page by appending a false extension to a URL. For example, http://mysite.local/page.fake. It should return the static 404 page and a 404 status code to the browser.
To test the custom 500 page, the simplest method is to break a connection string in App_Config\ConnectionStrings.config
. Edit the username to be incorrect. Any request should then return the custom 500.aspx page, with a 500 status code returned to the browser.
The package installs ~\400.html
and ~\500.aspx
. Update these files to include the site CSS and brand as needed. You may also wish to add additional logic to the 500 page to be specific to each site (by default there is one 500 error used for all sites).
- \bin\SitecoreFriendlyErrors.dll
- \App_Config\Include\Z.SitecoreFriendlyErrors.config
- \404.html
- \500.aspx
- \web.config
system.web\customErrors
system.webServer\handlers\Sitecore.MediaRequestHandler
system.webServer\httpErrors
All modifications are reverted if the package is uninstalled. Original Sitecore values will be reverted.
This package is based off my thorough posts on Sitecore Friendly Errors...