Sharepoint SPWeb重命名 - 异常SPException - 此页面的安全验证无效

时间:2009-11-04 22:44:07

标签: c# sharepoint-2007 sharepoint-api

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

1 个答案:

答案 0 :(得分: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;
        }
    }
});