After changing Blog permissions, subsequent attempts to save the Blog settings page fail with:
Failed to load viewstate.
The control tree into which viewstate is being loaded must match
the control tree that was used to save viewstate during the previous request.
The stack trace repeatedly ends in:
System.Web.UI.Control.LoadChildViewStateByIndex
System.Web.UI.Page.LoadAllState
The failure occurs before the Blog Update click handler executes.
Steps to reproduce
Install DNN Blog 6.7.1 on DNN Platform 10.3.2.
Create or open a Blog.
Open Edit Blog.
Change Blog permissions, for example grant permissions to Registered Users.
Save.
Reopen Edit Blog.
Change any Blog setting, such as Title or Syndication.
Click Update.
Expected result
The Blog settings save successfully.
Actual result
The request fails during ASP.NET viewstate restoration.
Root cause
BlogPermissionsGrid saves and restores the base viewstate for a dynamically generated permissions grid:
allStates[0] = base.SaveViewState();
and later:
base.LoadViewState(myState[0]);
After permission changes, the generated child controls can be recreated in a different positional order. ASP.NET then fails while restoring child viewstate by index.
Fix
Do not persist or restore the generated child-grid viewstate. Continue to persist only:
Blog ID
Current user ID
Blog permission collection
The affected file is:
Server/Core/Security/Controls/BlogPermissionsGrid.cs
Validation
The fix was tested successfully on:
an existing Blog;
a newly created second Blog;
repeated permission changes;
Blog title changes;
syndication changes;
new post creation;
post editing;
post image upload;
a production site running the stock DNN Blog 6.7.1 release.
The production test required replacing only:
DotNetNuke.Modules.Blog.Core.dll
No further viewstate errors occurred.
Environment
Problem
After changing Blog permissions, subsequent attempts to save the Blog settings page fail with: