【发布时间】:2014-03-22 06:20:02
【问题描述】:
Sitecore 6.5 系统: 在代码中,有没有办法确定哪些角色可以访问特定项目?
我设置了一个外联网,一些项目是“受保护的” - 这意味着匿名帐户的继承已被破坏,并且某些角色已被授予读取权限。我已经构建了一个自定义管道,因此我可以确定用户何时尝试查看受保护的项目,但我需要确定哪些角色有权查看该项目,以便我可以适当地指导他们。
谢谢, 萨德
编辑:
这是相关代码 - 可能有更好的方法(我继承了系统和代码),但我正在尝试利用已经存在的内容。下面代码的问题是,当用户没有权限时,Sitecore.Context.Item 为空。
public class NotFoundProcessor : Sitecore.Pipelines.HttpRequest.HttpRequestProcessor
{
public override void Process(Sitecore.Pipelines.HttpRequest.HttpRequestArgs args)
{
if (args.PermissionDenied)
{
//determine what role would give the user access
foreach(Sitecore.Security.Accounts.Role role in Sitecore.Security.Accounts.RolesInRolesManager.GetAllRoles())
{
bool roleCanRead = Sitecore.Context.Item.Security.CanRead(role);
//... do stuff here
}
}
}
}
【问题讨论】: