【发布时间】:2011-09-05 07:56:40
【问题描述】:
我想找到用户所属的组列表。我尝试了几种解决方案 http://www.codeproject.com/KB/system/everythingInAD.aspx 但没有结果。
这段代码给了我一个“真”,表示 LDAP 正在运行:
public static bool Exists(string objectPath)
{
bool found = false;
if (DirectoryEntry.Exists("LDAP://" + objectPath))
found = true;
return found;
}
谢谢,
更新 1:
public ArrayList Groups(string userDn, bool recursive)
{
ArrayList groupMemberships = new ArrayList();
return AttributeValuesMultiString("memberOf", "LDAP-Server",
groupMemberships, recursive);
}
public ArrayList AttributeValuesMultiString(string attributeName,
string objectDn, ArrayList valuesCollection, bool recursive)
{
DirectoryEntry ent = new DirectoryEntry(objectDn);
PropertyValueCollection ValueCollection = ent.Properties[attributeName];
IEnumerator en = ValueCollection.GetEnumerator();
while (en.MoveNext())
{
if (en.Current != null)
{
if (!valuesCollection.Contains(en.Current.ToString()))
{
valuesCollection.Add(en.Current.ToString());
if (recursive)
{
AttributeValuesMultiString(attributeName, "LDAP://" +
en.Current.ToString(), valuesCollection, true);
}
}
}
}
ent.Close();
ent.Dispose();
return valuesCollection;
}
我有一个例外:
PropertyValueCollection ValueCollection = ent.Properties[attributeName];
“COMException 未处理”
【问题讨论】:
-
在您链接的文章中,有一个“获取用户组成员资格”部分...您尝试过吗?
-
你能发布不适合你的代码吗?
-
顺便说一句,在这种情况下,true 意味着对象存在,而不是 LDAP 正在运行。也许您应该了解一些有关 LDAP 和 Active Directory 的基本知识。
-
你会在这里找到另一个post with the same question的链接。
标签: c# active-directory