DirectorySearcher.FindOne() fails when LDAP path contains "/"

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I have a method that is used to find all of the distribution lists and
security groups that a user belongs to. This works fine, except when the
LDAP
path looks like the following:

CN=aaa/ aaaaa,OU=Distribution Lists,DC=string,DC=string,DC=string,DC=com

I've found that everytime the DirecotrySearcher.FindOne() encounters a path
that contains a '/' in the CN portion, it throws an exception. Below is the
exception:

Source: System.DirectoryServices
Message: Unknown error (0x80005000)
Stack Trace: at System.DirectoryServices.DirectoryEntry.Bind(Boolean
throwIfFail)
at System.DirectoryServices.DirectoryEntry.Bind()
at
System.DirectoryServices.DirectoryEntry.get_AdsObject()
at
System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)
at
System.DirectoryServices.DirectorySearcher.FindOne()
at ADUtilityTester.ADUtilities.getDLList(String
sDomain, String sUser) in c:\\documents and settings\\username\\my
documents\\visual studio projects\\adutilitytester\\adutilities.cs:line 74

Line 74 is:

SearchResult schRes = ds2.FindOne();

I've tried escaping it, but then it just doesn't find anything.

Any ideas on how to get around this problem?
 
I have a method that is used to find all of the distribution lists and
security groups that a user belongs to. This works fine, except when the
LDAP path looks like the following:

CN=aaa/ aaaaa,OU=Distribution Lists,DC=string,DC=string,DC=string,DC=com

The forward slash is a special character that LDAP normally uses for
internal purposes, as a separator between certain bits of the LDAP
string. That's why it gets confused if an object name suddenly
contains a /

You can try to "escape" it with a \ - so replace your forward slash
with a backslash-forward slash combo.

This also applies to a number of other special chars in LDAP, such as
comma (,), dot (.), equal sign (=), and a few more.

Marc
================================================================
Marc Scheuner May The Source Be With You!
Berne, Switzerland m.scheuner -at- inova.ch
 
Back
Top