【发布时间】:2011-04-06 11:43:33
【问题描述】:
我在更新 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();
}
}
}
});
【问题讨论】:
-
您的代码在哪里运行?功能接收器? Web 部件?
-
它在用户控件中运行,该控件被烘焙到页面布局中。
标签: sharepoint elevated-privileges