Navigating to a page containing an IAjaxControl instance with the same UniqueID causes "Validation of ViewState MAC failed" exception.


Here's an example of when this particular situation can occur: Page 1 has a single instance of an Update region on it with the ID property NOT set on it. Likewise, Page 2 has the very same. Also, both UpdateRegion's are nested the same on both pages so they have the same UniqueID. When navigating from Page 1 to Page 2 with the DiskStateStrategy configured for use a "Validation of ViewState MAC failed" exception will be thrown (and most likely won't be handled so the default ASP.NET exception page will be shown).
This happens in the context described above because of these 2 factors:
  1. The DiskStateStrategy, assuming that it is configured for use, will try and reference a .state file of the same name for both UpdateRegions since the UniqueID property of the control is what is used for generating a "unique" file name. When Page 2 is loaded and the StateStrategy tries to load the ViewState of the UpdateRegion from Page 1 the exception is thrown.
  2. The "LoadControlState" method of the CallbackStrategy class tries to load stale ViewState when !ParentPage.IsPostBack. Without exception, when a page is requested and !IsPostBack, ViewState should not be loaded.
    Resolution of #2 will remedy the issue, but to achieve maximum robustness, both #1 and #2 will be resolved in a future revision of the source code. #1 will be resolved by generating a more correctly unique file name for .state files while #2 will be resolved by ensure the "Load" method of the configured StateStrategy is not invoked when !ParentPage.IsPostBack.
Closed May 2, 2010 at 2:34 AM by peanutbutterlou
This has been resolved by, strangely enough, ensuring the StateStrategy saves upon initial load.