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.