Title: ASP.NET AJAX 1.0 RTM Bug
Slug: asp-net-ajax-1-0-rtm-bug
Date: 2007-02-26 15:15:00
Author: Kartones
Lang: en
Tags: Development, Troubleshooting, ASP.NET
Description: About a bug in ASP.NET AJAX 1.0 RTM that causes server errors due to RoleManagerModule cookies, and a few solutions.

 <p>For a few days, I'm doing some QA and testing at work of a web application that some of my companions have been developing.</p>
<p>The application has typical technologies (SQL Server 2005, ASP.NET 2.0, a bit of Active Directory, master pages, ...) and it also uses <a href="http://ajax.asp.net/">ASP.NET AJAX</a>. The entire website was built with the early versions, porting  to beta and now running with the 1.0 RTM.</p>
<p> All was going well until the RTM upgrade (made few weeks ago). The app. started to  throw some exceptions from time to time, but they thought it was because of the development server (an old laptop which stores a Virtual Machine with the "real" DB and web server).  When I joined to do the QA and testing, I started to get the errors almost every few minutes, making the application crash frecuently.</p>
<p>The exception we got was this:</p>
<p><font face="courier new,courier">Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. <br>The status code returned from the server was: 12029</font> </p>
<p> As the official documentation for the error <a href="http://ajax.asp.net/docs/ClientReference/Sys.WebForms/Exceptions/PageRequestManagerServerErrorException.aspx">is crappy</a>, we searched and searched <a href="http://forums.asp.net/thread/1555817.aspx">until we found the solution</a>.</p>
<p>Seems that there's a bug in the RTM version of ASP.NET AJAX (not present in earlier versions) with the <font face="courier new,courier">RoleManagerModule</font> when it adds its cookie to <font face="courier new,courier">Response</font>'s cookies.</p>
<p>There are 3 ways to evade the bug. None is perfect but the first one worked well for us and required no code rewriting:</p>
<ol>
<li>Disable caching of cookies in the RoleManager.<br><font face="courier new,courier"><font color="blue">&lt;</font><font color="maroon">roleManager</font><font color="red"> enabled</font><font color="blue">="true"</font><font color="red"> cacheRolesInCookie</font><font color="blue">="false"&gt;</font></font><br></li>
<li>Handle the Application's Error event to clear the error from the Context selectively.<br><font face="courier new,courier"><font color="blue">void </font><font color="black">Application_Error(</font><font color="blue">object </font></font><font color="black" face="courier new,courier">sender, EventArgs e) <br>{<br>  </font><font face="courier new,courier"><font color="darkgreen">//There should be some checking done so that not all the errors <br>  //are cleared<br>  </font><font color="black">Context.ClearError()</font></font><font face="courier new,courier"><font color="blue">;<br></font><font color="black">}</font></font><br></li>
<li>Disable EventValidation in the web form.<br><font face="courier new,courier"><font color="blue">&lt;</font><font color="maroon">%@</font><font color="red"> Page Language</font><font color="blue">="C#"</font><font color="red"> EnableEventValidation</font><font color="blue">="false"</font><font color="red"> %</font><font color="blue">&gt;</font></font></li></ol>
<p>Hope helps someone else if they have the same problem</p>
