RunWithElevatedPrivileges の下にある SharePoint の PublishingWeb 属性の更新に問題があります。「pubWeb.IncludeInCurrentNavigation = false;」という行で「このページのセキュリティ検証は無効です」という例外で失敗します。以下は、実行しようとしているコードです。通常、AllowUnsafeUpdates = true を設定できますが、publishingWeb にはこの特別なプロパティがありません。
私の質問は、昇格したコンテキストで PublishingWeb 属性を更新する適切な方法は何ですか?
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite siteCollection = new SPSite(parentSiteUrl))
{
//siteCollection.AllowUnsafeUpdates = true;
using (SPWeb web = siteCollection.OpenWeb(subSiteUrl))
{
//web.AllowUnsafeUpdates = true;
if (PublishingWeb.IsPublishingWeb(web))
{
// hide new sub-site from navigation elements.
PublishingWeb pubWeb = PublishingWeb.GetPublishingWeb(web);
pubWeb.IncludeInCurrentNavigation = false;
pubWeb.IncludeInGlobalNavigation = false;
pubWeb.Update();
}
}
}
});