Frage

I am trying to get a list of all attributes for a given LDAP entry, with the following code:

LdapConnection conn = GetOpenLdapConnection();

string filter = "(uid=" + user + ")";
SearchRequest search = new SearchRequest(LDAP_BASE, filter, SearchScope.Subtree, "*");
SearchResponse resp = conn.SendRequest(search) as SearchResponse;

SearchResultEntry entry = resp.Entries[0];
Console.WriteLine(entry.DistinguishedName);
foreach (string attr in entry.Attributes.AttributeNames)
    Console.WriteLine("Name:" + attr);

conn.Dispose();

However, this only prints one attribute name: "uid". I'm confused as to why this is not returning all of the attributes that I can clearly see using an LDAP browser (browsing the same entry for the given user as the code is attempting to retrieve).

Honestly, I don't care to see all the attributes; I know the names of the ones I want to retrieve, but even if I replace new SearchRequest(..., "*") with new SearchRequest(..., "attr1", "attr2", "etc."), the only one I can seem to retrieve is "uid". Is there something obvious here I am missing?

War es hilfreich?

Lösung

Wow, in my function GetOpenLdapConnection(), I needed to set the AuthType for the LdapConnection to Basic. Now everything seems to be working correctly. Hope this helps someone else.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top