Custom Error pages (Server 500)

Sukhwant Atwal asked on November 16, 2017 12:22

Hi All,

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 also 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?

Recent Answers


Brenden Kehren answered on November 16, 2017 18:17

Your best bet is to use a straight HTML page and not a server page like aspx. IIS can serve this up without needing the .net framework and it won't need to be precompiled either.

Now to your problem, I believe the problem is Kentico is trying to process the page /SitePages/Errors/error500.aspx as a portal page. So you need to do a few things:

  • place that file in a directory in which you can target with the second bullet point
  • tell Kentico to not process that directory.

Best bet is to place your error500.aspx page in say this directory /sitecodename/noprocess/. Then in Kentico Settings>URLs and SEO>URL Format, add the path to that directory in the Excluded URLs textbox. This will tell Kentico to not process the pages in that directory.

1 votesVote for this answer Mark as a Correct answer

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