views:

189

answers:

2

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?

+1  A: 

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.

Matthew Jones
+1  A: 

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)
    {
    }
}
John