API
Version 7.x > API > Handling general errors for multiple sites with multiple designs View modes: 
User avatar
Member
Member
iacido-gmail - 1/30/2014 1:44:28 PM
   
Handling general errors for multiple sites with multiple designs
Hi friends,

I'm dealing with a small issue here, basically I would like to custom an error page for a specific website. I can handle that without problems for 404 not found pages, but for error 500, I could not find any solution.

Each website has its own design templates, so we would like to have each website its own 500 Error page.

Is there way to accomplish that?

Here is what I have done so far:

I created a SystemEvent Handler this is the code:
using System;

using CMS.SettingsProvider;
using CMS.CMSImportExport;
using CMS.DocumentEngine;
using CMS.GlobalHelper;
using CMS.EmailEngine;

/// <summary>
/// Summary description for CMSSystemEvents
/// </summary>
[CustomSystemEvents]
public partial class CMSModuleLoader
{
/// <summary>
/// Attribute class that ensures the loading of custom handlers
/// </summary>
private class CustomSystemEventsAttribute : CMSLoaderAttribute
{
/// <summary>
/// Called automatically when the application starts
/// </summary>
public override void Init()
{
// Assigns custom handlers to the appropriate events
SystemEvents.Exception.Execute += System_Exception_Execute;
}

private void System_Exception_Execute(object sender, SystemEventArgs e)
{
// Kentico automatically logs the Exception into kentico logs.
// Nothing to do here.

// We will use the CMS.EmailProvider to send e-mails
EmailMessage email = new EmailMessage();

email.From = "localhost@domain.local";
email.Recipients = "personalemail@gmail.com;
email.Subject = "Testing";
email.Body = "Error exception";
EmailSender.SendEmail(email);
}
}
}

everything works just find, it sends the email correctly when an exception occurred.

I added these lines to the webconfig:
<httpErrors existingResponse="Auto" errorMode="Custom">
<clear />
<error statusCode="500" redirect="~/CMSTemplates/SampleSite/Errors/Exception.aspx" />
</httpErrors>

The issue here is that when I access a demo page that is throwing an exception I got the email, but it did not redirect me to the Exception.aspx template, also how can I code it in a way to handle multiple websites with multiple designs.

I also tried to redirect the user inside the handler right after send the email, but URLHelper and any other way to redirect was not possible.

Any suggestions, ideas are always welcome.

Thanks in advance.

User avatar
Certified Developer 10
Certified Developer 10
josha-bpstudios - 1/30/2014 3:00:56 PM
   
RE:Handling general errors for multiple sites with multiple designs
Could you do a redirect that points to a page in your tree. If you put each page under the same folder in each site, you may be able to fetch the domain or site name and create the response url. IE in each site have a folder named Pages that contains a page titled ErrorPage. when you are trying to reference the url, try building the url off of the domain of the site or sitename so your url will be "www.mysite.com/Pages/ErrorPage.aspx"

Is this what you are wanting?

User avatar
Member
Member
iacido-gmail - 1/30/2014 4:47:54 PM
   
RE:Handling general errors for multiple sites with multiple designs
Right! that is exactly what I wanted.

In fact I ended doing that.

Thanks in advance :)