0

尝试 SPWeb 重命名时,我收到以下 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

知道这里可能有什么麻烦吗?以下是相关代码:

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

1 回答 1

2

1) 设置 SPWeb.AllowUnsafeUpdates = true
2) 您可能需要使用 ValidateFormDigest 验证 FormDigest

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;
        }
    }
});
于 2009-11-04T23:00:26.177 回答