我正在使用ELMAH進行錯誤記錄,並且如果錯誤發生在部分回發期間(來自包裝在更新面板中的控件的事件處理程序),那麼它將記錄錯誤兩次。我不使用「MsAjaxDeltaErrorLog」模塊,而是以編程方式記錄來自ScriptManager控件的「AsyncPostBackError」事件處理程序的錯誤。我這樣做是爲了避免重定向到泛型頁面,以避免在部分回發期間發生錯誤。我在web.config中關閉了重定向。這裏是記錄異常由ELMAH記錄兩次的Ajax錯誤
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)));
}
}