Tutorial :Sharepoint SPWeb rename - Exception SPException - The security validation for this page is invalid



Question:

When attempting an SPWeb rename I receive the following SPException:

Exception SPException - The security validation for this page is invalid.  Click Back in your Web browser, refresh the page, and try your operation again. - Failed to create workgroup registration entry  

Any idea what might be the troubles here? Here is the relevant code:

SPSecurity.RunWithElevatedPrivileges(() =>           {               using (SPWeb thisWeb = site.OpenWeb(webUrl))               {                     thisWeb.Title = newName;                   thisWeb.Update();               }            });  


Solution:1

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;          }      }  });  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »