在Active Directory中,如何获取一个用户所属的组的组名?

heatwin 2003-08-19 01:18:32
有可能一个用户属于多个组,用代码如何实现?谢谢!
...全文
87 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
qiujinwen 2003-08-21
  • 打赏
  • 举报
回复
DirectoryEntry group = new DirectoryEntry("LDAP://CN=Sales,DC=Fabrikam,DC=COM");
object members = group.Invoke("Members",null);
foreach( object member in (IEnumerable) members)
{
DirectoryEntry x = new DirectoryEntry(member);
Console.WriteLine(x.Name);
}

qiujinwen 2003-08-21
  • 打赏
  • 举报
回复
看这样行不行
DirectoryEntry x = new DirectoryEntry(member);
heatwin 2003-08-21
  • 打赏
  • 举报
回复
up
heatwin 2003-08-19
  • 打赏
  • 举报
回复
谢谢qiujinwen(..迷惑..) ,不过有个问题再问:在获得组名的同时,还获得该组的属性名,上面的代码又如何改呢?
qiujinwen 2003-08-19
  • 打赏
  • 举报
回复
DirectoryEntry entry = new DirectoryEntry("LDAP://BLACK.COM/CN=SSS,OU=Test,DC=Black,DC=Com")
System.DirectoryServices.PropertyCollection pro;
pro = entry.Properties;
foreach(object member in pro["memberOf"])
{
string memberName = member.ToString();
}
heatwin 2003-08-19
  • 打赏
  • 举报
回复
ding

110,574

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧