Sharepoint 2010 SPImport.运行安全异常
本文关键字:安全 异常 运行 SPImport 2010 Sharepoint | 更新日期: 2023-09-27 18:11:57
我想使用SPExport(工作正常)和SPImport将一个web复制到另一个位置。我正在使用Sharepoint Foundation 2010中的应用程序页面。此代码在Button click事件中执行。
using (SPWeb web = site.OpenWeb(sourceWebUrl))
{
SPExportSettings exportSettings = new SPExportSettings();
exportSettings.FileLocation = exportPath;
exportSettings.BaseFileName = exportFileName;
exportSettings.SiteUrl = site.Url;
exportSettings.ExportMethod = SPExportMethodType.ExportAll;
exportSettings.FileCompression = true;
exportSettings.IncludeVersions = SPIncludeVersions.All;
exportSettings.IncludeSecurity = SPIncludeSecurity.All;
exportSettings.ExcludeDependencies = false;
exportSettings.ExportFrontEndFileStreams = true;
exportSettings.OverwriteExistingDataFile = true;
SPExportObject expObj = new SPExportObject();
expObj.IncludeDescendants = SPIncludeDescendants.All;
expObj.Id = web.ID;
expObj.Type = SPDeploymentObjectType.Web;
exportSettings.ExportObjects.Add(expObj);
SPExport export = new SPExport(exportSettings);
export.Run();
}
using (SPWeb web = site.OpenWeb(destinationWebUrl))
{
web.AllowUnsafeUpdates = true;
SPImportSettings importSettings = new SPImportSettings();
web.FileLocation = exportPath;
web.BaseFileName = exportFileName;
web.IncludeSecurity = SPIncludeSecurity.All;
web.UpdateVersions = SPUpdateVersions.Overwrite;
web.RetainObjectIdentity = false;
web.SiteUrl = site.Url;
web.WebUrl = web.Url;
web.Validate();
SPImport import = new SPImport(importSettings);
import.Run();
web.AllowUnsafeUpdates = false;
}
异常"此页的安全验证无效。在Web浏览器中单击"返回",刷新页面,然后再次尝试操作。当调用SPImport.Run()时抛出。
我没能找到解决这个问题的方法,既没有在应用程序页面上添加FormDigest控件,也没有在目标web上允许不安全的更新。
同样,从控制台应用程序运行这段代码工作正常,但如果代码从应用程序页运行,它不工作(即使提高了安全性)。
任何帮助都会很感激。谢谢。
通过添加
SPUtility.ValidateFormDigest();