我想查找用户所在的组列表。我尝试了几种解决方案,从 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是未处理”
在您链接的文章中,有一个“获取用户组成员”部分...你试试看吗? –
可以吗? st代码不适合你吗? – baalazamon
顺便说一下,在这种情况下,true意味着该对象存在,而不是LDAP正在运行。也许你应该了解一些关于LDAP和Active Directory的基本知识。 –