Is there a .NET class that can parse CN= strings out of LDAP?

后端 未结 7 577
梦毁少年i
梦毁少年i 2020-12-17 18:15

I\'ve got a string that I\'m fetching from LDAP for Active Directory group membership and I need to parse it to check if the user is a member of the AD group. Is there a cl

7条回答
  •  春和景丽
    2020-12-17 18:43

    Using System.DirectoryServices;
    
    namespace GetGroups
    {
        public string GetGroupName(string LDAPGroupEntry)
        {
            // LDAPGroupEntry is in the form "LDAP://CN=Foo Group Name,DC=mydomain,DC=com"
            DirectoryEntry grp = new DirectoryEntry(LDAPGroupEntry);
            return grp.Properties["Name"].Value.ToString();
        }
    }
    

提交回复
热议问题