3

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 ^^

gjdass
  • 146
  • 7
  • The cn is the username, and not the short name (i.e. Mike Figgis, and not mfiggis). I would recommend using objectCategory rather than objectClass simply for speed of searching (objectCategory is indexed) – Anya Shenanigans Jul 11 '13 at 11:42
  • Yey, i knew that for CN. But CN is right. In ADLDS, the CN is 'user1'. Thanks for the tip with ObjectCategory ;) I didn't know. – gjdass Jul 11 '13 at 14:13
  • Did you try tu use a wildcard and see if it returns any result ? – Geod24 Jul 11 '13 at 14:55
  • Ok, another mystical thing, when i try with '(&(objectClass=user)(mail=*))', it doesn't work ... Evenif it's mail tag used. With an address instead of '*', it works (like before). WTF – gjdass Jul 11 '13 at 15:08
  • My fault, wildcard is working for mails. – gjdass Jul 11 '13 at 15:28

1 Answers1

0

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 !

gjdass
  • 146
  • 7