1

I want to query Active Directory in a .NET Core project and get details of a user by providing the user id.

LDAP server path is in this format: ldap://

1 Answer 1

5

The LDAP URLs specifies the server you want to use and the query to perform. For instance, in the query:

ldap://ds.example.com:389/dc=example,dc=com?givenName,sn,cn?sub?(uid=john.doe) 
  • ds.example.com:389 comprises the LDAP server and port.
  • dc=example,dc=com is the base DN
  • givenName,sn,cn are the attributes to include in the result,
  • sub is the scope, and
  • (uid=john.doe) is the query

There is an LDAP library in .NET, that is not included in .NET Core. You may use the Novell LDAP libraries to query an LDAP and/or Active Directory Server in .NET Core. The documentation is available at Novell.

The documentation for the Novell library mentions the LDAP URLs. If you have LDAP URLs, I think you must split the URL to obtain each part and perform the query.


Getting information of a user

Using the Novell library, you can can connect to the server and perform LDAP queries using attributes of the entries such as in queries like (givenName=John), (!givenName=John) or (givenName=Jo*). You may check the example code here, here and here.

In Windows / Active Directory, the login name is stored in sAMAccountName. You can use a query like

(&(objectClass=user)(objectClass=person)(sAMAccountName={0}))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.