Connecting to LDAP Server from .NET

前端 未结 1 1023
深忆病人
深忆病人 2021-01-03 11:09

I\'ve been recommended to use System.DirectoryServices.Protocols to be able to support connecting to LDAP servers other than Active Directoy here.
Unfortu

相关标签:
1条回答
  • 2021-01-03 11:22

    I suspect the main problem might be: samAccountName is a strictly Windows-only attribute that other LDAP servers won't know about.

    So if you're going against a non-Active Directory LDAP, you should use something else for searching - e.g. sn (for surname or last name), givenName (first name), possibly displayName.

    Another interesting option might be to use ANR (ambiguous name resolution) searches - see this page on SelfADSI roughly in the middle, where ANR is explained.

    With ANR, you would write your query like this:

    string ldapSearchFilter = 
       string.Format("(&(ObjectCategory={0})(anr={1}))", "person", username);
    

    I also changed ObjectClass to ObjectCategory for two reasons:

    • ObjectCategory is single-valued, e.g. only contains a single value (ObjectClass is multi-valued)
    • ObjectCategory is typically indexed, and thus searches are typically a lot faster using ObjectCategory

    Does this return the results you're looking for?

    0 讨论(0)
提交回复
热议问题