我試圖讀出用戶,這些用戶有權讀取文檔。我已經可以連接到目錄並讀出身份參考,但是現在我想在Active Directory中查看ID並從此ID中讀出姓名。如何在Active Directory中查找IdentityReference?
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());
我已經可以連接到AD服務器,現在我想用DirectorySearcher搜索IdentityReference。
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
我該怎麼做?
btw:我是C#初學者,對每個答案都非常感謝。