C# 如何在Active Directory中查找标识引用?

C# 如何在Active Directory中查找标识引用?,c#,active-directory,C#,Active Directory,我正在尝试读取用户,他们有权读取文档。我已经可以连接到目录并读取标识引用,但现在我想在Active directory中查找ID并从该ID中读取名称 DirectorySecurity ds = Directory.GetAccessControl(path); AuthorizationRuleCollection arc = ds.GetAccessRules(true, true, typeof(System.Security.Principal.

我正在尝试读取用户,他们有权读取文档。我已经可以连接到目录并读取标识引用,但现在我想在Active directory中查找ID并从该ID中读取名称

DirectorySecurity ds = Directory.GetAccessControl(path);
                     AuthorizationRuleCollection arc = ds.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount));
                     foreach (FileSystemAccessRule fsar in arc)
                     {
                             StringBuilder sb = new StringBuilder();
                             sb.AppendLine("Identity : " + fsar.IdentityReference.Value);


                             sb.AppendLine("FileSystemRights : " + fsar.FileSystemRights);
                             + fsar.PropagationFlags);


                             Console.WriteLine(sb.ToString());
我已经可以连接广告服务器了,现在我想用DirectorySearcher搜索标识引用

 System.DirectoryServices.DirectoryEntry entry = new System.DirectoryServices.DirectoryEntry(@"LDAP://mydomain.local/");
                              entry.Username = username;
                              entry.Password = password;

                             System.DirectoryServices.DirectorySearcher mySearcher = new System.DirectoryServices.DirectorySearcher(entry);

mySearcher.Filter = "(......)"; //searching for IdentityReference
我该怎么做

顺便说一句:我是一个C#初学者,对每一个答案我都心存感激。

正如你所看到的,身份引用要么是SID(S-1-2-3434-1234243…),要么是NT帐户名(DOMAIN\john.doe)。可以使用
Translate
方法将它们相互转换,因此您可以使用任何一种方法。决定你喜欢哪一个并做翻译。如果参考文献已经是这种格式,这并不重要,翻译总是比较容易,你可以确定它会是你喜欢的任何形式

对于基于这些属性中的任何一个来查找用户,我建议使用该方法。它支持SID和登录名查找等功能,并且比LDAP筛选器容易得多

当然,如果愿意,您可以编写LDAP筛选器。我不确定登录名,因为它不是以那种格式直接存储在AD中的,但是如果您为
objectSid
属性编写查询,您肯定可以搜索SID,如
(objectSid=S-1-2-3434…