Sharepoint error: Enable-SPFeature : The security validation for this page is invalid

Sharepoint error: Enable-SPFeature : The security validation for this page is invalid

当我尝试通过 PowerShell 部署项目时,PS 继续执行 "Enable-SPFeature" 操作, 然后打印以下错误消息:

Enable-SPFeature : The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again. At E:\Demo\DemoProject\DemoProject\scripts\utility.ps1:315 char:19 + Enable-SPFeature <<<< -identity $id -url $url -confirm:$false + CategoryInfo : InvalidData: (Microsoft.Share...etEnableFeature:SPCmdletEnableFeature) [Enable-SPFeature], SPException + FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletEnableFeature

谁能提供解决方案?

每当我们更新任何列表项、列表或 SPWeb 实例时,您可能会得到 "The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again"。这是因为在更新对内容数据库的修改时进行了一些安全验证,因此,为了避免该异常,我们必须使 SPWeb 实例的 AllowUnsafeUpdates 属性 为真。

SPWeb oWeb = new SPWeb();

oWeb.AllowUnsafeUpdates = true;

AllowUnsafeUpdates 属性 用于获取或设置一个布尔值,指定是否允许更新数据库作为 GET 请求的结果或不需要安全验证。 SPSite class 也有这个 属性.