使用 AJAX 进行 ASP.Net healthMonitoring

发布于 2024-07-23 06:18:03 字数 1079 浏览 6 评论 0原文

目前,在我们所有的环境中,我们都打开了健康监控,以便在用户引起错误时向我们发出警报:

<healthMonitoring enabled="true">
  <providers>
    <add name="MailWebEventProvider" type="System.Web.Management.SimpleMailWebEventProvider" to="[email protected]" from="[email protected]" buffer="false" subjectPrefix="prefix: "/>
  </providers>
  <rules>
    <add name="All errors from my site" eventName="All Errors" provider="MailWebEventProvider" profile="Critical"/>
  </rules>
</healthMonitoring>

我们最近开始实现更多 AJAX 功能,我刚刚意识到部分页面更新期间抛出的任何错误都不会触发健康监控发送电子邮件。 用户得到默认的alert()消息框; 但是,服务器端没有任何内容。

有谁知道如何打开此功能? 我不确定我缺少什么设置

编辑

我看到 ScriptManager 控件有一个名为“AsyncPostBackError”的事件。 如果我挂上这个并执行“抛出 e.Exception”,它将触发运行状况监视器; 但是,它会消除用户看到的错误。 有谁知道如何在不抛出这样的错误的情况下触发健康监视器?

Currently, in all of our environments we have healthmonitoring turned on to alert us when ever a user has caused an error:

<healthMonitoring enabled="true">
  <providers>
    <add name="MailWebEventProvider" type="System.Web.Management.SimpleMailWebEventProvider" to="[email protected]" from="[email protected]" buffer="false" subjectPrefix="prefix: "/>
  </providers>
  <rules>
    <add name="All errors from my site" eventName="All Errors" provider="MailWebEventProvider" profile="Critical"/>
  </rules>
</healthMonitoring>

We recently started implementing more AJAX functionality, and I just realized any error thrown during a partial page update does not trigger the healthmonitor to send the email. The user gets the default alert() message box; however, nothing on the server side.

Does anyone know how to turn this on? I'm not sure what setting I'm missing

Edit

I see that the ScriptManager control has an event called "AsyncPostBackError". If I hook onto this and do "throw e.Exception", it will fire off the health monitor; however, it erases the error the user sees. Does anyone know how to fire the health monitor without throwing an error like this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

风月客 2024-07-30 06:18:03

不确定这是否是您正在寻找的内容,但在查看此处,此处,以及此处,看起来您可以创建可以从后台代码调用的自定义 Web 事件。 因此,您可以从导致部分页面回发的函数中调用这些处理程序,从而在服务器上留下通知。

特别检查第一个链接; 它详细介绍了如何构建自定义网络事件。

Not sure if this is what you are looking for, but after looking here, here, and here, it looks like you can create custom web events that you can call from your code behind. So, you can call these handlers from the functions causing the partial page postback to leave a notification on the server.

Check the first link especially; it details how to build a custom web event.

愿得七秒忆 2024-07-30 06:18:03

根据 Matthew 的建议,我想出了这个:

protected void ScriptManager1_AsyncPostBackError(object sender, AsyncPostBackErrorEventArgs e)
{
    ((ScriptManager)sender).AsyncPostBackErrorMessage = e.Exception.Message;

    WebBaseEvent.Raise(new AjaxWebErrorEvent(e.Exception.Message, null, 100123, e.Exception)); 
}

AjaxWebErrorEvent 是这样的:

public class AjaxWebErrorEvent : WebRequestErrorEvent
{
    public AjaxWebErrorEvent(string message, object eventSource, int eventCode, System.Exception e) 
        : base(message, eventSource, eventCode, e)
    {
    }
}

Going with Matthew's suggestions, I came up with this:

protected void ScriptManager1_AsyncPostBackError(object sender, AsyncPostBackErrorEventArgs e)
{
    ((ScriptManager)sender).AsyncPostBackErrorMessage = e.Exception.Message;

    WebBaseEvent.Raise(new AjaxWebErrorEvent(e.Exception.Message, null, 100123, e.Exception)); 
}

Where AjaxWebErrorEvent is this:

public class AjaxWebErrorEvent : WebRequestErrorEvent
{
    public AjaxWebErrorEvent(string message, object eventSource, int eventCode, System.Exception e) 
        : base(message, eventSource, eventCode, e)
    {
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文