1

获取给定 id 的 objectClass 名称的最佳方法是什么。

我的输入应该是“IDNSKF”我的输出应该是组或个人或计算机..

我使用以下代码,但有时distinguishedName我找不到OU=Groups虽然对象是组

代码:

DirectoryEntry de = new DirectoryEntry("LDAP://local.be");
        DirectorySearcher searcher = new DirectorySearcher(de);
        searcher.Filter = "(&(cn=variable))";
        searcher.SearchScope = SearchScope.Subtree;
        searcher.PropertiesToLoad.Add("distinguishedName");
        SearchResult result = searcher.FindOne();
        string s = result.GetDirectoryEntry().Properties["distinguishedName"].Value.ToString();
        if (s.IndexOf("OU=Groups") > -1)
            return Groups;
        if (s.IndexOf("OU=Users") > -1)
            return Users;
        if (s.IndexOf("OU=Computers") > -1)
            return Computer;

谢谢

4

1 回答 1

1

我想与您分享我找到的解决方案:

SearchResult result = directorySearcher.FindOne();
        if (result == null)
            return new LocalPermissionEntry(accessRule);

        ResultPropertyValueCollection userValueCollection = result.Properties["objectClass"];

        // check if the entry is a group or a user.
        if (userValueCollection.Contains("group"))
            return new GroupPermissionEntry(accessRule);
        if (userValueCollection.Contains("person") || userValueCollection.Contains("user"))
            return new UserPermissionEntry(accessRule);

        return new LocalPermissionEntry(accessRule);
于 2013-02-08T14:35:34.393 回答