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

后端 未结 7 607
梦毁少年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条回答
  •  猫巷女王i
    2020-12-17 19:01

    If you don't want to add additional dependencies and just want to parse the string..

    This type of string can easily be parsed just using string.Split. To get the CN values, would be something like..

    string[] split = "CN=Foo Group Name,DC=mydomain,DC=com".Split(',');
    List cnValues = new List();
    foreach(string pair in split){
        string[] keyValue=pair.Split('=');
        if(keyValue[0]=="CN")
           cnValues.Add(keyValue[1]);
    }
    

提交回复
热议问题