Exploring the depths and potentials of ASP.NET RSS 2.0 or Subscribe to .BenRush by Email
 Friday, March 09, 2007

Say you have a situation where you want to catch all unhandled web errors in your global.asax file. You reimplement part of your site in ASP.Net AJAX and suddenly some exceptions that were being caught are no longer caught, the question is, what's happening?

The answer lies within the PageRequestManager: the server-side "brains" of ASP.Net AJAX. This object is a control just like any other when used on an ASP.Net page and registers for errors on the page within it's OnInit() method:

if (_owner.IsInAsyncPostBack) {
_owner.IPage.Error += OnPageError;
}

The IPage reference is a reference to a page wrapper that ASP.Net AJAX uses internally; suffice it to say that it's simply registering for the event fired when an unhandled exception occurs on a page - that part is nothing new to AJAX.  

What happens, though is that the following block of code gets executed within the OnPageError() handler if you do not have custom errors redirect enabled:

if (showAsyncErrorMessage) {
_owner.IPage.Response.Clear();
EncodeString(_owner.IPage.Response.Output, ErrorToken, httpCode.ToString(CultureInfo.InvariantCulture), errorMessage);
_owner.IPage.Response.End();
}

The page response gets cleared, a special blob of text gets inserted, and then the response stream ends. Doing this effectively wipes the page response (including any error information in it) away - thereby short-circuiting the ability for your handler method in Global.asax to get called.

Run Fiddler on your machine to see the kind of stuff that gets pushed back to the browser when an error is handled by this OnPageError() method, it's a simple '|' seperated string.

If you wish to get your handler to work in the Global.asax file again, you must add some kind of <customErrors> redirect page - this drives the execution flow differently through the PageRequestManager object and leaves the error information together for your global error handler(s).


kick it on DotNetKicks.com
Friday, March 09, 2007 2:48:00 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
Under the Hood
Tracked by:
"Network Marketing Opportunities" (Network Marketing Opportunities) [Trackback]
"Software Development Guide" (Software Development Guide) [Trackback]

Computers Blogs - Blog Top Sites

Archive
<January 2009>
SunMonTueWedThuFriSat
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567
Blogroll
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2009
Benjamin Rush
Sign In
Statistics
Total Posts: 444
This Year: 0
This Month: 0
This Week: 0
Comments: 128
Themes
Pick a theme:
All Content © 2009, Benjamin Rush
DasBlog theme 'Business' created by Christoph De Baene (delarou)