Link to home
Start Free TrialLog in
Avatar of zhshqzyc
zhshqzyc

asked on

AD search: not found

Hello,

I search a username in AD. The user does exist but I can't find it.
Why?
 string UserNameCreated = UserNameTextBox.Text;
            DirectoryEntry entry = new DirectoryEntry("LDAP://cfs");
            entry.AuthenticationType = AuthenticationTypes.Secure;

            DirectorySearcher deSearch = new DirectorySearcher(entry);
            deSearch.Filter = "(&(objectClass=user)(cn=" + UserNameCreated + "))";

            SearchResultCollection results = deSearch.FindAll();

Open in new window

Step through the code and I find
deSearch.Filter=(&(objectClass=user)(cn=hzzzz))

Open in new window

results.Count=0
ASKER CERTIFIED SOLUTION
Avatar of KenMcF
KenMcF
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of zhshqzyc
zhshqzyc

ASKER

It seems to be working, so you mean that CN is the legacy attribute?
CN is common Name. So the format is usually one of these formats not the users logon name "Firstname LastName" "LastName, FirstName"

http://www.rlmueller.net/Name_Attributes.htm
May I retrieve the cn and samaccountname from the code and compare them?
I am new to AD.
I am not that familiar with .net but you should be able to within your code. You will just need to add cn and samaccountname to the properties you want to pull from the user objects and then compare.