我正在循環瀏覽網絡目錄並嘗試輸出與每個文件/文件夾關聯的用戶/組名(權限)。我得到SID的後面,但我想要的名稱,如「group_test」,而不是「S-1-5-32-544」。這裏是我的代碼 -將SID轉換爲用戶名/組?
var files = Directory.GetFiles(path, "*.*", SearchOption.TopDirectoryOnly);
foreach (var f in files2)
{
var fileInfo = new FileInfo(f);
var fs = fileInfo.GetAccessControl(AccessControlSections.Access);
foreach (FileSystemAccessRule rule in fs.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount)))
{
var value = rule.IdentityReference.Value;
Response.Write(string.Format("File: {0} \t Usergroup: {1} <br/>", fileInfo.Name, value));
} }
我得到SID的從上面的代碼,但在foreach循環中,如果我用這個代替 -
(NTAccount)((SecurityIdentifier)rule.IdentityReference).Translate(typeof(NTAccount)).Value
我得到這個例外 - Some or all identity references could not be translated.
看樣子Translate方法在遠程共享上不起作用。我如何檢索SID的真實姓名?遠程服務器沒有LDAP。
謝謝。