Reputation: 21751
I am writing a performance-sensitive piece of code that will query an LDAP directory where it may be common to not find the object requested (a user or group).
We are using System.DirectoryServices.Protocols.LdapConnection.SendRequest() to submit the query.
If the group/user is not found, SendRequest() throws a DirectoryOperationException. Since this is performance sensitive, I would really like to avoid exceptions because of the performance hit for handling them.
Is there an alternate way to query LDAP such that I can get a null/false/empty collection result instead of an exception?
(I didn't see anything obvious like TrySendRequest, but I am not very familiar with LDAP filter syntax, so I thought perhaps there is something I'm missing)
Upvotes: 0
Views: 147
Reputation: 27871
You can use the DirectorySearcher class.
It's FindAll method returns an empty collection if it doesn't find any result.
And it's FindOne method returns null if it does not find a match.
I am not sure about performance though. You need to test to see if using DirectorySearcher
enhances the performance.
Upvotes: 1