Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.Net healthMonitoring with AJAX

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?

like image 450
John Avatar asked Nov 17 '25 01:11

John


2 Answers

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.

like image 99
Matthew Jones Avatar answered Nov 19 '25 16:11

Matthew Jones


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)
    {
    }
}
like image 29
John Avatar answered Nov 19 '25 15:11

John



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!