Skip to content

Latest commit

 

History

History
59 lines (42 loc) · 2.86 KB

MSAjax.md

File metadata and controls

59 lines (42 loc) · 2.86 KB
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 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:

{% highlight c# %} private void OnPageError(object sender, EventArgs e) { ... if (flag) { ... this._owner.IPage.Response.End(); } } {% endhighlight %}

The Solution

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.

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:

  1. The unhandled exception must occur during a Partial PostBack
  2. It must occur before the OnInit method of System.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.