c# – Active Directory列表OU
发布时间:2020-12-15 08:43:53 所属栏目:百科 来源:网络整理
导读:我目前有这个代码, string defaultNamingContext; DirectoryEntry rootDSE = new DirectoryEntry("LDAP://RootDSE"); defaultNamingContext = rootDSE.Properties["defaultNamingContext"].Value.ToString(); rootDSE = new DirectoryEntry("LDAP://" + defa
我目前有这个代码,
string defaultNamingContext; DirectoryEntry rootDSE = new DirectoryEntry("LDAP://RootDSE"); defaultNamingContext = rootDSE.Properties["defaultNamingContext"].Value.ToString(); rootDSE = new DirectoryEntry("LDAP://" + defaultNamingContext); //DirectoryEntry domain = new DirectoryEntry((string)"LDAP://" + defaultNamingContext); DirectorySearcher ouSearch = new DirectorySearcher(rootDSE,"(objectCategory=Organizational-Unit)",null,SearchScope.Subtree); MessageBox.Show(rootDSE.Path.ToString()); try { SearchResultCollection collectedResult = ouSearch.FindAll(); foreach (SearchResult temp in collectedResult) { comboBox1.Items.Add(temp.Properties["name"][0]); DirectoryEntry ou = temp.GetDirectoryEntry(); } } 当我使用调试器时,我可以看到rootDSE.Path实际指向正确的位置,在这种情况下DC = g-t-p,DC = Local但目录搜索器找不到任何结果.有人可以帮忙吗? 解决方法
斯蒂芬 – 我的坏 – 由于某种原因,使用objectCategory的搜索不起作用.
即使objectCategory显示为CN = Organizational-Unit,对于搜索,您仍然需要使用与objectClass相同的值: 所以尝试使用过滤器(objectCategory = organizationalUnit) – 这绝对适合我! 更新:为了在搜索结果中获取某些属性(为了在组合框中显示它们),您需要在创建DirectorySearcher时包含这些属性: DirectorySearcher ouSearch = new DirectorySearcher(rootDSE); ouSearch.Filter = "(objectCategory=Organizational-Unit)"; ouSearch.SearchScope = SearchScope.Subtree; ouSearch.PropertiesToLoad.Add("name"); // add more properties if you want to ... 有了这个,你绝对应该能够获取temp.Properties [“name”] [0]并将其粘贴到组合框的项目列表中. 我真的没看到你需要什么线 DirectoryEntry ou = temp.GetDirectoryEntry(); 抓住名称属性….. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- SQlite Android数据库的应用 Android SQLite 简易
- spi flash、nor flash 、nand flash简单学习
- 跨界合作,掌阅科技联手PAGEONE书店找寻阅读的力
- flex学习笔记
- [学习笔记] 用TexturePacker建立动画Animation
- ruby-on-rails – 创建自定义Sprockets处理器的文
- 异常: IOException parsing XML document from
- .net – Visual Basic:使用OR进行变量赋值
- react native 调用Android原生方法
- TypeScript Webpack解析symlink文件夹中的依赖项
热点阅读