如何在c#中的objectGUID属性之后在Active Directory中搜索?

时间:2017-12-21 16:04:34

标签: c# active-directory

我试图根据guid从Active Directory中的本地数据库中找到我的用户。 我们在Active Directory中的Guid属性是一个16字节的数组,我将其作为16个hexa数字的字符串存储在db中:78-21-B5-51-76-C8-7C-45-95-E5-53 -5F-B8-15-05-90。 搜索结果如下:

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();

每次结果都为空。 我尝试使用byte类型的数组进行搜索,但Filter看起来像这样:(&(objectcategory = user)(objectguid = System.Byte []))

0 个答案:

没有答案
相关问题