【发布时间】:2023-03-30 12:37:02
【问题描述】:
我正在使用 ELMAH 进行错误记录,如果错误发生在部分回发期间(来自更新面板中包含的控件的事件处理程序),那么它会记录两次错误。我没有使用“MsAjaxDeltaErrorLog”模块,而是以编程方式记录来自 ScriptManager 控件的“AsyncPostBackError”事件处理程序的错误。我这样做是为了避免在部分回发期间发生错误重定向到通用页面。我在 web.config 中关闭了重定向。这是记录异常的代码
protected void ScriptManager1_AsyncPostBackError(object sender, AsyncPostBackErrorEventArgs e)
{
HttpContext.Current.Items["AjaxError"] = "Ajax";
ErrorSignal.FromCurrentContext().Raise(e.Exception,HttpContext.Current);
}
and in Global.asax, I am redirecting manually
protected void ErrorLog_Logged(object sender, ErrorLoggedEventArgs e)
{
if (!HttpContext.Current.Items.Contains("AjaxError"))
{
var pageName = e.Entry.Error.StatusCode == 404 ? "FileNotFoundPage" : "GenericErrorPage";
var redirectPage = ConfigurationManager.AppSettings[pageName];
Response.Redirect(String.Format("{0}?ExceptionId={1}&ExceptionMessage={2}", redirectPage, Server.UrlEncode(e.Entry.Id),
Server.UrlEncode(e.Entry.Error.Message)));
}
}
【问题讨论】:
标签: asp.net error-handling elmah