title | layout | permalink | article |
---|---|---|---|
Using ELMAH with ASP.NET AJAX |
page |
a/msajax/ |
true |
This article describes the MsAjaxDeltaErrorLogModule
that was introduced with ELMAH 1.0 BETA 3.
The first incarnation of ASP.NET AJAX written against v2.0 of the .NET Framework (v1.0.61025.0) is unfortunately not 100% compatible with ELMAH. When an unhandled exception occurs during a Partial PostBack, the original code catches the exception, and unceremoniously calls Response.End()
, preventing ELMAH from capturing it. This code can be seen from Reflector by looking in System.Web.Extensions.dll
at the System.Web.UI.PageRequestManager.OnPageError
method:
{% highlight c# %} private void OnPageError(object sender, EventArgs e) { ... if (flag) { ... this._owner.IPage.Response.End(); } } {% endhighlight %}
To overcome this you can add the MsAjaxDeltaErrorLogModule
to your application as follows:
{% highlight xml %} {% endhighlight %}
This module checks to see if the current request is a Partial PostBack, and if so sets up an alternative handler to capture any unhandled exception.
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:
- The unhandled exception must occur during a Partial PostBack
- It must occur before the
OnInit
method ofSystem.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.
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.