代码之家  ›  专栏  ›  技术社区  ›  Chris Ballance

SharePoint SPWeb重命名-异常异常异常-此网页的安全验证无效

  •  0
  • Chris Ballance  · 技术社区  · 15 年前

    尝试SPWeb重命名时,我收到以下异常:

    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 回复  |  直到 15 年前
        1
  •  2
  •   9b5b    15 年前

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