I suspect that the main problem may be: samAccountName is strictly a Windows attribute that other LDAP servers are not aware of.
So, if you are going against LDAP without Active Directory, you should use something else to search - for example. sn (for last name or last name), givenName (first name), possibly displayName .
Another interesting option would be to use ANR queries (ambiguous name resolution) - see this page on SelfADSI around the middle where ANR explained.
With ANR, you should write your query as follows:
string ldapSearchFilter = string.Format("(&(ObjectCategory={0})(anr={1}))", "person", username);
I also changed ObjectClass to ObjectCategory for two reasons:
ObjectCategory is unique, for example. contains only one value ( ObjectClass is multi-valued)ObjectCategory usually indexed, and therefore the search is usually much faster using ObjectCategory
Does this return the results you are looking for?
source share