2

I am trying to find my users from local db in Active Directory based on a guid. The Guid property that we have in Active Directory is an array of 16 byte's, that I store in db as a string of 16 hexa numbers: 78-21-B5-51-76-C8-7C-45-95-E5-53-5F-B8-15-05-90. The search looks like this:

var adPath = "LDAP://" + ConfigurationManager.AppSettings["ActiveDirectoryServer"];
DirectoryEntry entry = new DirectoryEntry(adPath, domainUsername, password);
entry.AuthenticationType = AuthenticationTypes.Secure;
var search = new DirectorySearcher(entry);
        search.Filter = string.Format("(&(objectcategory=user)({0}={1}))", "objectguid", guid);
        search.PropertiesToLoad.Add("directReports");
        search.PropertiesToLoad.Add("Description");
        search.PropertiesToLoad.Add("mail");
        search.PropertiesToLoad.Add("manager");
        search.PropertiesToLoad.Add("givenName");
        search.PropertiesToLoad.Add("sn");
        search.PropertiesToLoad.Add("objectGUID");
        var testUser = search.FindOne();

The results are null every time. I'we tried making the search with an array of type byte but the Filter would look like this: (&(objectcategory=user)(objectguid=System.Byte[]))

Zupermi
  • 31
  • 1
  • 3
  • This answer should help: https://stackoverflow.com/questions/11613772/how-i-can-find-a-user-with-the-guidobjectguid-parameter-in-active-directory. However I do recommend to connect using server binding LDAP://domainorserverfqdn/ – oldovets Dec 22 '17 at 07:05
  • thanks, the binding thing works just fine :) – Zupermi Dec 22 '17 at 13:16

0 Answers0