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[]))