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?
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();
Step through the code and I finddeSearch.Filter=(&(objectClass=user)(cn=hzzzz))
results.Count=0
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
http://www.rlmueller.net/Name_Attributes.htm
ASKER
May I retrieve the cn and samaccountname from the code and compare them?
I am new to AD.
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.
ASKER