ELMAH 记录了两次 Ajax 错误
我使用 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)));
}
}
I am using ELMAH for error logging and if the error occurs during partial postback (from an event handler of a control wrapped in an update panel), then it is logging the errors twice. I am NOT using the "MsAjaxDeltaErrorLog" module, but instead programmatically logging the errors from "AsyncPostBackError" event handler of ScriptManager control. I am doing this to avoid redirection to generic page for errors occurred during partial postbacks. I turned off redirection in web.config. here is the code that logs the exception
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)));
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自 Elmah 网站:
(http://code.google.com/p/elmah/wiki/MSAjax)< /a>
我处于与您相同的位置,每次我收到异步错误时,我都会将问题记录两次,但我猜除非我们修改 ELMAH 的源代码,否则我会陷入困境
From Elmah website:
(http://code.google.com/p/elmah/wiki/MSAjax)
Im on the same position you are, and everytime I get a asyn error I get the problem logged twiced, but I guess were stuck unless we modify ELMAH's source code