开发者

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

开发者 https://www.devze.com 2022-12-10 02:14 出处:网络
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 th

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


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号