Kentico 利用 Page not Found 事件
Kentico tapping into Page not Found event
我的任务是在 Kentico 项目中记录在我们的数据库中找不到的异常和页面。对于未找到的页面,我需要点击 "CMSRequestEvents.End.After" 事件。此事件接收发件人和事件参数。我如何破解事件参数并查找页面未找到相关内容?由于所有请求都会触发此事件,因此我只需要处理 "page not found" 并记录它。 SystemEvents.Exception.Execute
在发生异常时被触发,找不到页面也不是异常。我们正在使用 Kentico 版本 7。
[CustomHandleError]
public partial class CMSModuleLoader
{
private class CustomHandleErrorAttribute : CMSLoaderAttribute
{
/// <summary>
/// Called automatically when the application starts
/// </summary>
public override void Init()
{
// Assign custom handlers to the appropriate events
SystemEvents.Exception.Execute += System_Exception_Execute;
CMSRequestEvents.End.After += Request_End_After;
}
private void System_Exception_Execute(object sender, SystemEventArgs e)
{
try
{
var exception = e.Exception;
var errorloggerHelper = new ErrorLoggerHelper();
errorloggerHelper.LogError(exception);
}
catch
{
//do nothing
}
}
private void Request_End_After(object sender, EventArgs e)
{
//since this gets called for each request, HANDLE only "page not found" and log
}
}
}
我假设 "our database" 你指的是 Kentico 以外的数据库。
由于 Kentico 已经记录了 "Page Not Found" 事件,我建议附加到 EventLogInfo.TYPEINFO.Events.Insert.After
事件并按 EventCode=="PAGENOTFOUND"
过滤,如 documentation.
中所述
截图(v8):
另一种选择是利用 custom error pages。
我的任务是在 Kentico 项目中记录在我们的数据库中找不到的异常和页面。对于未找到的页面,我需要点击 "CMSRequestEvents.End.After" 事件。此事件接收发件人和事件参数。我如何破解事件参数并查找页面未找到相关内容?由于所有请求都会触发此事件,因此我只需要处理 "page not found" 并记录它。 SystemEvents.Exception.Execute
在发生异常时被触发,找不到页面也不是异常。我们正在使用 Kentico 版本 7。
[CustomHandleError]
public partial class CMSModuleLoader
{
private class CustomHandleErrorAttribute : CMSLoaderAttribute
{
/// <summary>
/// Called automatically when the application starts
/// </summary>
public override void Init()
{
// Assign custom handlers to the appropriate events
SystemEvents.Exception.Execute += System_Exception_Execute;
CMSRequestEvents.End.After += Request_End_After;
}
private void System_Exception_Execute(object sender, SystemEventArgs e)
{
try
{
var exception = e.Exception;
var errorloggerHelper = new ErrorLoggerHelper();
errorloggerHelper.LogError(exception);
}
catch
{
//do nothing
}
}
private void Request_End_After(object sender, EventArgs e)
{
//since this gets called for each request, HANDLE only "page not found" and log
}
}
}
我假设 "our database" 你指的是 Kentico 以外的数据库。
由于 Kentico 已经记录了 "Page Not Found" 事件,我建议附加到 EventLogInfo.TYPEINFO.Events.Insert.After
事件并按 EventCode=="PAGENOTFOUND"
过滤,如 documentation.
截图(v8):
另一种选择是利用 custom error pages。