MS AJAX: Root Cause Analysis
The MS AJAX Framework is great! It abstracts a lot of great AJAX functionality away from the nitty-gritty javascript and into the .Net development world. That said, though, there are a few situations where determining the root cause of an error can be problematic.
An example of a difficult error to troubleshoot can be located here. Essentially, if HTML becomes malformed (as far as the AJAX engine is concerned) during an Asynchronous postback, you get a javascript alert that says the following:
"Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
Details: Error parsing near "
This error message makes sense if you are doing any of the operations it says NOT to do - like using Response.Write(), for instance. What about the situations where you've wracked your brain and you cannot determine where you have gone wrong?
For those troublesome situations, I like to use Nikhil Kothari's Web Development Helper. Simply turning the HTTP logging on, I was able to see exactly what was being returned from the server for the partial postback. In my situation, it appears that when the error was thrown, the response showed the normal page response:
8671|updatePanel|ctl00_ContentPlaceHolder2_upCreateUserWizard|
<table>.....</table>
But then it also threw a Runtime error page after the returned HTML:
|<html>
<head>
<title>Runtime Error</title>
<style>....
After checking my error logging, the message is:
"System.Web.HttpException: Server cannot modify cookies after HTTP headers have been sent.
at System.Web.HttpCookieCollection.Add(HttpCookie cookie)
at System.Web.Security.RoleManagerModule.OnLeave(Object source, EventArgs eventArgs)...."
This helped to validate (to me, anyway) that it is indeed an issue with the RoleCaching. The fix, unfortunately, isn't great - as it requires you to turn off Role Caching altogether.
I guess you win some and lose some. The win, in this case, was that we were able to conclusively determine what the issue was - the loss, of course, was the workaround.
I'd be interested in reading how other people have debugged issues like this.