简体   繁体   English

DirectorySearcher适用于邮件,但不适用于cn C#

[英]DirectorySearcher works for mail, but not for cn C#

I'm french so please be indulgent with my poor english :P 我是法国人所以请放纵我可怜的英语:P

I have a problem when i want to retrieve a user by CN against LDAPS. 当我想通过CN对LDAPS检索用户时,我遇到了问题。

This code works fine when i want to retrieve users by mail, but not by cn ... Don't understand why. 当我想通过邮件检索用户时,此代码工作正常,但不是通过cn ...不明白为什么。 When i run my research with ldp.exe, both are good, with the same search string ! 当我使用ldp.exe运行我的研究时,两者都很好,具有相同的搜索字符串! it's just in C# it doeasn't work, just with CN. 它只是在C#中它不起作用,只有CN。

String strFilter = "(&(objectClass=person)(cn=user1))";
//String strFilter = "(&(objectClass=person)(mail=user1@sps.dev))";
objSearchADLDS = new DirectorySearcher(objADLDS);
objSearchADLDS.Filter = strFilter;
objSearchADLDS.SearchScope = SearchScope.Subtree;
SearchResult result = objSearchADLDS.FindOne();

I really don't understand ... result is null when i search by cn, and is OK when i search by mail ... >< 我真的不明白...当我用cn搜索时结果为空,并且当我通过邮件搜索时可以...> <

If someone could help with this error, it would be great ^^ 如果有人可以帮助解决这个错误,那就太棒了^^

Ok, i just found answer to this problem yesterday evening. 好的,我昨天晚上刚刚找到了这个问题的答案。

The problem was a bad authentication against DirectoryEntry... Because of this, DirectorySearcher was searching in wrong way. 问题是针对DirectoryEntry的身份验证错误...因此,DirectorySearcher正在以错误的方式进行搜索。

Simple solution, my fault. 简单的解决方案,我的错。 One entire day to find one line. 一整天找一条线。

Thanks to all ! 谢谢大家 !

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM