我是新手ELMAH
,但我想尝试将 GUID 传递给错误页面。
我尝试了本文所讨论的内容,但无法触发 ErrorLog_Logged。任何想法为什么会发生这种情况。我是否需要在 web.config 文件中添加一些额外的配置?(对于下面代码的格式,提前抱歉,无法正确显示)。
谢谢,
这是我的 web.config 文件的内容:
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="telerik.web.ui">
<section name="radScheduler" type="Telerik.Web.UI.RadSchedulerConfigurationSection, Telerik.Web.UI" allowDefinition="MachineToApplication" requirePermission="false"/>
<section name="radCompression" type="Telerik.Web.UI.RadCompressionConfigurationSection, Telerik.Web.UI, PublicKeyToken=121fae78165ba3d4" allowDefinition="MachineToApplication" requirePermission="false"/>
</sectionGroup>
<sectionGroup name="elmah">
<section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah"/>
<section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
<section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
<section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah"/>
</sectionGroup>
这是我的global.asax
文件的内容
void ErrorLog_Logged(object sender, ErrorLoggedEventArgs args)
{
//if (args.Entry.Error.Exception is HandledElmahException)
// return;
var config = WebConfigurationManager.OpenWebConfiguration("~");
var customErrorsSection = (CustomErrorsSection)config.GetSection("system.web/customErrors");
if (customErrorsSection != null)
{
switch (customErrorsSection.Mode)
{
case CustomErrorsMode.Off:
break;
case CustomErrorsMode.On:
FriendlyErrorTransfer(args.Entry.Id, customErrorsSection.DefaultRedirect);
break;
case CustomErrorsMode.RemoteOnly:
if (!HttpContext.Current.Request.IsLocal)
FriendlyErrorTransfer(args.Entry.Id, customErrorsSection.DefaultRedirect);
break;
default:
break;
}
}
}
void FriendlyErrorTransfer(string emlahId, string url)
{
Response.Redirect(String.Format("{0}?id={1}", url, Server.UrlEncode(emlahId)));
}