Kentico CMS 6.0 Developer's Guide

Configuring custom error pages

Configuring custom error pages

Previous topic Next topic Mail us feedback on this topic!  

Configuring custom error pages

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

There are several possible reasons why you might wish to configure the system to display custom pages instead of standard error messages. This can help reduce the inconvenience caused to visitors if they encounter an error while browsing your website, and also improves the security of the site by hiding potentially sensitive internal data (e.g. code in stack traces). You can create custom pages for this purpose with any kind of content, such as an apology or additional instructions, and then configure the system to ensure that they are displayed in the appropriate situations.

 

One of the most common problems is the Page not found error (404 HTTP status code). A custom error page that will be shown as a response may be specified directly through the site settings. Simply go to Site Manager-> Settings -> Content and enter the URL into the Page not found URL field, for example: ~/CMSMessages/CustomNotFound.aspx

 

devguide_clip1116

 

 

 

Adding the error page

 

When creating a custom error page, it is recommended to add it directly into your web project as an .aspx file, e.g. under the CMSMessages folder. The actual content may be defined to match your specific requirements, but keep in mind that an error page should always return the appropriate HTTPResponse status code (404 in this case).

 

Since Kentico CMS is a standard ASP.NET application, the general handling of errors and exceptions can be configured by editing the <customErrors> section of your web.config file.

 

<system.web>

...

   <customErrors defaultRedirect="~/CMSMessages/error.aspx" mode="Off">

       <error statusCode="404" redirect="~/CMSMessages/PageNotFound.aspx" />

   </customErrors>

...

</system.web>

 

The mode attribute sets the basic error page behaviour. You may use the following possible values:

 

Off - in this mode, an error page containing details of the encountered error is displayed to all users (including the stack trace etc.). This is the default setting for Kentico CMS websites.

On - in this case, all users will see a simplified version of the error page with no technical details about the problem.

RemoteOnly - this option ensures that full error details are shown to the local host, but simplified error pages are displayed to everyone else, i.e. end users who access the site remotely.

 

If you wish to use a completely custom error page, set the mode to On or RemoteOnly and specify the URL through the defaultRedirect attribute. You may also add any number of child <error> elements to assign a different error page to individual types of HTTP errors. It is necessary to enter the HTTP response code of the given error into the statusCode attribute and the URL of the appropriate error page as the redirect value.