Skip to content

Instantly share code, notes, and snippets.

@jonschoning
Created July 28, 2011 16:33
Show Gist options
  • Save jonschoning/1111889 to your computer and use it in GitHub Desktop.
Save jonschoning/1111889 to your computer and use it in GitHub Desktop.
Sharepoint SPWeb rename - Exception SPException - The security validation for this page is invalid
//1) Set SPWeb.AllowUnsafeUpdates = true
//2) You may need to validate the FormDigest with ValidateFormDigest
SPSecurity.RunWithElevatedPrivileges(() =>
{
using (SPWeb thisWeb = site.OpenWeb(webUrl))
{
try
{
thisWeb.AllowUnsafeUpdates = true;
if (!thisWeb.ValidateFormDigest())
throw new InvalidOperationException("Form Digest not valid");
thisWeb.Title = newName;
thisWeb.Update();
}
finally
{
if(thisWeb != null)
thisWeb.AllowUnsafeUpdates = false;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment