Reputation: 1441
I am trying to query an LDAP server to find an LDAP user and import it into my system. However, when I try to do this, the request throws a DirectoryOperationException
, saying The object does not exist
.
ldapConnection.AuthType = AuthType.Negotiate;
if (ldapDomain.UseEncryption)
{
ldapConnection.SessionOptions.SecureSocketLayer = true;
ldapConnection.SessionOptions.StartTransportLayerSecurity(null);
}
var credentials = new NetworkCredential(loginName, password, ldapDomain.Name);
ldapConnection.Bind(credentials);
var filter = String.Format("(&(objectCategory=person)(objectClass=user)(anr={0})(!(UserAccountControl:1.2.840.113556.1.4.803:=2)))", loginName);
var request = new SearchRequest(containerDistinguishedName, filter, SearchScope.Subtree);
var response = ldapConnection.SendRequest(request) as SearchResponse;
var entry = response.Entries[0];
I only have to work against a Microsoft/Windows LDAP server. Right now, containerDistinguishedName
is empty, but could be filled in with values to further restrict the search filter.
Upvotes: 3
Views: 5428
Reputation: 11134
From the looks of this, an empty containerDistinguishedName
refers to the Root DSE, but a subtree
scoped search should still work, assuming the authorization state of the connection permits trawling the DIT (the Root DSE is only returned in the search result if the search sole was base
). Try using the base object that "tops" the DIT for containerDistinguishedName
, something like dc=example,dc=com
.
Upvotes: 3