RegisterRequiresControlState Error + Workaround

May 02, 2008 Digital Experience

Thanks to our great community we have discovered a hard-to-track bug that happens on websites with a greater amount of traffic. Since you may be experiencing this bug as well, we’ve decided to publish the workaround here on the blog as well as some background.

The error manifests itself every so often and the page you see looks like this:


The background

The bug happens mostly on websites with higher amounts of traffic and it happens when the same page is requested concurrently, at the very same moment. The problem is in the fact that even though the two pages are running in separate threads, the cache of the page that was requested first (and I mean first as in “just a bit” before the second one) is valid for the second page. The cache of the second page should not be valid for the first page, because it should be thread dependent, but it is. The particular error happens then as the first page progresses through its lifecycle, the second one enters that very same lifecycle and we get the “RegisterRequiresControlState can only be called before and during PreRender”.

The workaround

  • Add App_Code folder in the root of your application. 
  • Add the following class in App_Code.
1 public class CustomPageHandler : Telerik.Cms.Web.InternalPage     
2 {     
3      protected override void OnPreInit(EventArgs e)     
4      {     
5        Nolics.ORMapper.Base.ObDataCache.Current = null;     
6                base.OnPreInit(e);     
7      }   
8 }     
9  

 
  • Open ~/Sitefinity/cmsentrypoint.aspx file.
  • In the first line change the value of Inherits attribute from Telerik.Cms.Web.InternalPage to CustomPageHandler.
  • Restart your application.

The conclusion

We have already fixed this issue for the upcoming Service Pack 2, but we do understand this is a really big issue to some of you and we wanted to give you a workaround in case you need it right now or if you are not planning on upgrading to Service Pack 2 as soon as it is released.

We’d like to apologize to everyone who experienced the problem. We would also like to thank everyone who reported the issue and provided us with many details which enabled us to pinpoint this bug.

The Progress Team