[英].NET Core - Novell LDAP/AD - Group search for a user that he belongs to - Has anybody made it work?
My code given below is working well while searching groups for a user, but the problem is it returns only one group.下面给出的代码在为用户搜索组时运行良好,但问题是它只返回一个组。 My goal is to get all groups the user belongs to.我的目标是获取用户所属的所有组。 How can I get rid of this problem?我怎样才能摆脱这个问题? Any help will be much appreciated.任何帮助都感激不尽。
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;
}
}
After some research and study finally I have got a solution regarding the problem posted here.经过一番研究和研究,我终于找到了关于这里发布的问题的解决方案。 This workaround is enough to meet the requirement.此解决方法足以满足要求。
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 });
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.