我正在循环浏览网络目录并尝试输出与每个文件/文件夹关联的用户/组名(权限)。我得到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。
谢谢。