.NET Core - Novell LDAP/AD - 组搜索他所属的用户 - 有人成功了吗?
.NET Core - Novell LDAP/AD - Group search for a user that he belongs to - Has anybody made it work?
我下面给出的代码在为用户搜索组时运行良好,但问题是它 returns 只有一个组。我的目标是获取用户所属的所有组。我怎样才能摆脱这个问题?任何帮助将不胜感激。
LdapSearchResults lsc = (LdapSearchResults)ldapCon.Search(
"DC=adl,DC=local",
LdapConnection.ScopeSub,
"(sAMAccountName=" + Username + ")",
null,
false
);
while (lsc.HasMore())
{
try
{
var nextEntry = lsc.Next();
nextEntry.GetAttributeSet();
adGroups.Add(new ADUserSecurityGroupModel {
member = nextEntry.GetAttribute("memberOf").StringValue,
distinguishedName = nextEntry.GetAttribute("sAMAccountName").StringValue
});
}
catch (LdapException ex)
{
Console.WriteLine("Error: " + ex.ToString());
continue;
}
}
经过一番研究和研究,我终于找到了解决这里问题的方法。此解决方法足以满足要求。
LdapSearchResults lsc = (LdapSearchResults)ldapCon.Search(
OU=Dashboards,DC=adl,DC=local",
LdapConnection.ScopeSub,
"(&(objectClass=group)(member:1.2.840.113556.1.4.1941:=CN=" + UserFullName +
",OU=Company Name,DC=adl,DC=local))",
null,
false);
while (lsc.HasMore())
{
LdapEntry nextEntry = null;
try
{
nextEntry = lsc.Next();
}
catch
{
continue;
}
nextEntry.GetAttributeSet();
adGroups.Add(new ADUserSecurityGroupModel { cn =
nextEntry.GetAttribute("cn").StringValue });
};
我下面给出的代码在为用户搜索组时运行良好,但问题是它 returns 只有一个组。我的目标是获取用户所属的所有组。我怎样才能摆脱这个问题?任何帮助将不胜感激。
LdapSearchResults lsc = (LdapSearchResults)ldapCon.Search(
"DC=adl,DC=local",
LdapConnection.ScopeSub,
"(sAMAccountName=" + Username + ")",
null,
false
);
while (lsc.HasMore())
{
try
{
var nextEntry = lsc.Next();
nextEntry.GetAttributeSet();
adGroups.Add(new ADUserSecurityGroupModel {
member = nextEntry.GetAttribute("memberOf").StringValue,
distinguishedName = nextEntry.GetAttribute("sAMAccountName").StringValue
});
}
catch (LdapException ex)
{
Console.WriteLine("Error: " + ex.ToString());
continue;
}
}
经过一番研究和研究,我终于找到了解决这里问题的方法。此解决方法足以满足要求。
LdapSearchResults lsc = (LdapSearchResults)ldapCon.Search(
OU=Dashboards,DC=adl,DC=local",
LdapConnection.ScopeSub,
"(&(objectClass=group)(member:1.2.840.113556.1.4.1941:=CN=" + UserFullName +
",OU=Company Name,DC=adl,DC=local))",
null,
false);
while (lsc.HasMore())
{
LdapEntry nextEntry = null;
try
{
nextEntry = lsc.Next();
}
catch
{
continue;
}
nextEntry.GetAttributeSet();
adGroups.Add(new ADUserSecurityGroupModel { cn =
nextEntry.GetAttribute("cn").StringValue });
};