简体   繁体   中英

DirectorySearcher works for mail, but not for cn C#

I'm french so please be indulgent with my poor english :P

I have a problem when i want to retrieve a user by CN against LDAPS.

This code works fine when i want to retrieve users by mail, but not by cn ... Don't understand why. When i run my research with ldp.exe, both are good, with the same search string ! it's just in C# it doeasn't work, just with 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 ... ><

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.

Simple solution, my fault. One entire day to find one line.

Thanks to all !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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