Using ELMAH with ASP.NET AJAX
This article describes the MsAjaxDeltaErrorLogModule
that was introduced with ELMAH 1.0 BETA 3.
The Problem
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:
The Solution
To overcome this you can add the MsAjaxDeltaErrorLogModule
to your application as follows:
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.
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:
- 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.
.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.