As in the topic, I struggle with verifying my guid if it exists in LDAP. Guid was previously downloaded from AD and saved in SQL database. Now, for the needs of my application, I want to verify my GUID in AD if it exists. I wrote a piece of code that connects to AD and checks for the given object (adSearch.Filter = "(& (Name = John Smith 1))". In this case I am looking for Jan Kowalski 1 in the Name attribute and it works fine and many other attributes, eg userPrincipalName etc. As soon as I check the GUID I get adResults was null. adSearch.Filter = "(& (objectGUID = 5c9a13b7-288d-4fdf-856f-e9ccddb5631e))";
C#:
public static string GetGuid(string objectGuid, string objectClass)
{
DirectoryEntry adRoot = new DirectoryEntry(ConfigurationManager.AppSettings["LDAPConnection"], ConfigurationManager.AppSettings["LDAPUser"], ConfigurationManager.AppSettings["LDAPPass"]);
Object adsiObj = adRoot.NativeObject;
DirectorySearcher adSearch = new DirectorySearcher(adRoot);
//adSearch.Filter = "(&(objectGUID=" + queryGuid + "))";
adSearch.Filter = "(&(objectGUID=5c9a13b7-288d-4fdf-856f-e9ccddb5631e))";
//adSearch.Filter = "(&(Name=Jan Kowalski 1))";
SearchResult adResults = adSearch.FindOne();
var adObject = adResults.GetDirectoryEntry();
return adObject.Guid;
}
Last edited by a moderator: