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