Sitecore错误:AddFromTemplate - 需要添加访问权限

4
我正在尝试将一张图片添加到内容树中,但是在以下代码处出现了访问被拒绝的错误:
item.Add("New Node1"...
我的方法的完整代码如下:
Sitecore.Data.Database master;
master = Sitecore.Configuration.Factory.GetDatabase("master");
Item item = master.Items["/sitecore/Content/Media/Images/Places"];
//  item.Fields["Related Issues"].Value = "Asia and the Pacific";
if (item != null)
{
    // add a new Item based on  the Document Template
    Item itm = item.Add("New Node1", master.Templates[new ID(new Guid("EJ0F53DF-5486-4UF4-A2D1-64C119E419A5"))]);
    if (itm != null)
    {
        // report the Item path to the User
        Response.Write(itm.Paths.Path);
    }
}

1
确保上下文用户具有对父项的item:create访问权限。您可能需要使用安全用户切换器或安全禁用器。 - Ankit Agrawal
1个回答

11

用户所在的 Sitecore 上下文环境可能没有权限访问此部分内容树。请使用 Access Viewer 工具进行检查。如果如此,则可以像这样将方法包装在 Security Disabler 中:

using (new Sitecore.SecurityModel.SecurityDisabler())
{
  // enter your code here
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接