Creating Custom Error Pages

Mike Bilz asked on July 7, 2017 20:48

Hello Kentico Team,

I am a little stuck on how to create custom error pages for 500 and 503 errors.

Should I copy the existing Error.aspx page and alter it's code-behind file to make the error messages less specific? Or can I just create a simple aspx page with no code-behind file at all, and include some basic HTML content?

Ideally, these pages should only contain an error code, a description, and a link to the homepage.

Thanks in advance for the help.

-mike

Recent Answers


Brenden Kehren answered on July 7, 2017 21:11

You can create error pages within the Kentico content tree OR you can create your own pages within the file system. In the web.config, go to the <customErrors> node and add in child nodes for each error code and specify the location you want to send them to. For instance:

<error statusCode="500" redirect="~/CMSPages/Custom/500Error.aspx" /> <error statusCode="503" redirect="~/CMSPages/Custom/503Error.aspx" />

0 votesVote for this answer Mark as a Correct answer

Mike Bilz answered on July 7, 2017 23:05

Hi Brenden,

So if I create the pages inside the Kentico Content tree, would those links look like this?

<error statusCode="503" redirect="~/Utilities/Special-Pages/Service-Unavailable" />

Using the "live URL" of the page, or do I need to use the "Permanent URL" for something like this?

Thanks.

-mike

0 votesVote for this answer Mark as a Correct answer

Zach Perry answered on July 10, 2017 18:25

According to the documentation, It is recommended to add general error pages directly into your web project as .aspx files.

1 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on July 12, 2017 15:12

If you created them inside the content tree, you are correct. I did fail to mention this in my initial post, if your site is down your and someone generates an error, those pages will not render. So in most cases, it's best to create those pages in the file system or upload something to the media library that is an HTML file or something like that which is not dependent on Kentico to process it first.

0 votesVote for this answer Mark as a Correct answer

Sukhwant Atwal answered on November 13, 2017 13:33 (last edited on November 16, 2017 12:21)

Hi All,

I'm also having similar problems getting this to work. I want to create a custom Server 500 error page.

In my web config <error statusCode="500" redirect="~/SitePages/Errors/error500.aspx"/>

In my error500.aspx - Just static HTML and containing all the css required for the page.

error500.aspx.cs - Not sure what to put in here as I don't have any functionality in my aspx page. It looks like this...

using System;

using CMS.Base;
using CMS.DataEngine;
using CMS.Helpers;
using CMS.UIControls;

public partial class SitePages_Errors_error500 : MessagePage
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
}  

To test I'm throwing a exception on the page I'm trying to load, e.g. throw new Exception();

what I get on a browser is a normal Server Error message (not my custom page). In the URL of the page it does seem to go to my page but something else is breaking...

http://<localhost>/SitePages/Errors/error500.aspx?aspxerrorpath=/CMSPages/PortalTemplate.aspx

Any ideas? :)

I wasn't sure if I needed to copy the code in the default Error.aspx file?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.