ELMAH 记录了两次 Ajax 错误

发布于 2024-10-07 16:51:42 字数 1101 浏览 0 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深居我梦 2024-10-14 16:51:42

来自 Elmah 网站:
(http://code.google.com/p/elmah/wiki/MSAjax)< /a>

潜在问题

不幸的是,
MsAjaxDeltaErrorLogModule 不是
完美的解决方案。由于它的方式
作品,有一个非常小的
出现错误的可能性
在 ELMAH 内登录两次。为此
发生时,必须发生以下情况:

  1. 未处理的异常必须发生在部分回发期间
  2. 它必须发生在 OnInit 方法之前
    System.Web.UI.PageRequestManager 是
    打电话。

这意味着标准
ELMAH 模块和
MsAjaxDeltaErrorModule 将捕获
例外。

事实上,这种情况的可能性
发生的事情将会是公平的
苗条。 .NET框架3.5

Microsoft Ajax 的更新版本
随 3.5 版本一起提供
.NET框架。这个新版本
改变了意外错误的方式
在部分回发中进行了处理,
删除对 Response.End 的调用。
因此,如果您继续使用
MsAjaxDeltaErrorLogModule 与此
框架的版本,你会看到
Partial 中所有未处理的错误
回发在 ELMAH 中被记录两次。*

我处于与您相同的位置,每次我收到异步错误时,我都会将问题记录两次,但我猜除非我们修改 ELMAH 的源代码,否则我会陷入困境

From Elmah website:
(http://code.google.com/p/elmah/wiki/MSAjax)

Potential Issues

Unfortunately, the
MsAjaxDeltaErrorLogModule is not a
perfect solution. Due to the way it
works, there is an extremely small
possibility that errors will get
logged twice within ELMAH. For this to
occur, the following must happen:

  1. The unhandled exception must occur during a Partial PostBack
  2. It must occur before the OnInit method of
    System.Web.UI.PageRequestManager is
    called.

This will mean that both the standard
ELMAH modules and the
MsAjaxDeltaErrorModule will capture
the exception.

In reality, the chances of this
happening are going to be fairly
slender. .NET Framework 3.5

An updated version of Microsoft Ajax
was shipped with version 3.5 of the
.NET Framework. This new version
changed the way that unexpected errors
in Partial PostBacks were handled,
removing the call to Response.End.
Therefore, if you continue to use the
MsAjaxDeltaErrorLogModule with this
version of the framework, you will see
all unhandled errors in Partial
PostBacks being logged twice in ELMAH.*

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文