2011-10-22 4 views
1

は、私は別の場所にあるWebをコピーする([OK]を働いている)SPExportとSPImportを使用します。私はSharepoint Foundation 2010のアプリケーションページを使用しています。このコードは、ボタンクリックイベントで実行されます。SharePoint 2010のSPImport.Runセキュリティ例外

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で安全でない更新を許可することもできません。

また、Console Applicationからこのコードを実行すると問題なく動作しますが、アプリケーションページからコードが実行されているとセキュリティが強化されていても機能しません。

ご協力いただければ幸いです。ありがとう。

答えて

2

は、溶液中にラインで1

+0

おめでとうを

SPUtility.ValidateFormDigest(); 

を追加することによって、これを行うことができました。あなたができるときは、他の人があなたの成功から学ぶかもしれないようにあなたの答えを「受け入れられた」とマークしてください。乾杯〜 –

+1

特権を昇格している人のために、これを前に行う必要があります。 http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.utilities.sputility.validateformdigest(v=office.14).aspx – trgraglia

関連する問題