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

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?
 
M

Marc Scheuner [MVP ADSI]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top