AD组文件夹访问

时间:2012-10-24 11:24:37

标签: permissions active-directory directory subdirectory

我有两个AD组作为Group1和Group2。我通过Windows应用程序将相同的用户添加到这些组。我有文件夹说abc我附加AD Group1。在abc中,我创建了一个子文件夹abcd,并通过禁用继承属性来附加AD Group2。当尝试使用用户凭据访问该文件夹时,我可以访问abc但是当尝试访问abcd文件夹时因访问被拒绝而获得异常。这个例外的原因是什么,解决方案是什么?

1 个答案:

答案 0 :(得分:0)

您可以随时测试以查看用户是否是第1组和第2组的成员....

这样的事情:

// set up domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

// find a user
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, "SomeUserName");

if(user != null)
{
GroupPrincipal group1 = GroupPrincipal.FindByIdentity(ctx, "group1");

if(group1 != null)
{
   bool userIsMemberOfGroup1 = user.IsMemberOf(group1);
}

GroupPrincipal group2 = GroupPrincipal.FindByIdentity(ctx, "group2");

if(group2 != null)
{
   bool userIsMemberOfGroup2 = user.IsMemberOf(group2);
}
}

这样,您永远不需要枚举用户所属的所有组 - 只检查您感兴趣的那些组,

您应该查看System.DirectoryServices.AccountManagement(S.DS.AM)命名空间。在这里阅读所有相关内容:

新的S.DS.AM让您可以轻松地与AD中的用户和群组一起玩!