重复GetAccessRules,FileSystemAccessRule条目

我从以下代码中获取了一个重复的FileSystemAccessRule:

C:\inetpub\wwwroot\AspInfo\Account BUILTIN\IIS_IUSRS : Allow : ReadAndExecute, Synchronize BUILTIN\IIS_IUSRS : Allow : -1610612736 NT SERVICE\TrustedInstaller : Allow : FullControl NT SERVICE\TrustedInstaller : Allow : 268435456 

我无法弄清楚它是什么或为什么。

并且显示的权限与我可以看到的文件FileManager属性不匹配。 例如,如何从此迭代或类似迭代中找到“列出文件夹内容”权限。 如果有人知道.NET文档中的示例,那将会有所帮助。

 protected void directoryInfo() { var di = new DirectoryInfo(Server.MapPath("/")); foreach (DirectoryInfo dir in di.GetDirectories()) { Response.Write(dir.FullName + "
"); DirectorySecurity ds = dir.GetAccessControl(); foreach (FileSystemAccessRule fsar in ds.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount))) { string userName = fsar.IdentityReference.Value; string userRights = fsar.FileSystemRights.ToString(); string userAccessType = fsar.AccessControlType.ToString(); Response.Write(userName + " : " + userAccessType + " : " + userRights + "
"); } } }

您将获得inheritance规则和在该文件夹上显式设置的规则的单独规则条目。 根据每个规则的传播设置,也会有所不同。 例如,您可以将一组权限设置为传播到子文件夹,将另一组权限设置为文件夹中的文件。 您的代码也在您似乎只想要访问权限(DACL)的文件夹上获取审核规则(SACL)。

试试这个:

 protected void directoryInfo() { var di = new DirectoryInfo(Server.MapPath("/")); foreach (DirectoryInfo dir in di.GetDirectories()) { Response.Write(dir.FullName + "
"); DirectorySecurity ds = dir.GetAccessControl(AccessControlSections.Access); foreach (FileSystemAccessRule fsar in ds.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount))) { string userName = fsar.IdentityReference.Value; string userRights = fsar.FileSystemRights.ToString(); string userAccessType = fsar.AccessControlType.ToString(); string ruleSource = fsar.IsInherited ? "Inherited" : "Explicit"; string rulePropagation = fsar.PropagationFlags.ToString(); string ruleInheritance = fsar.InheritanceFlags.ToString(); Response.Write(userName + " : " + userAccessType + " : " + userRights + " : " + ruleSource + " : " + rulePropagation + " : " + ruleInheritance + "
"); } } }

您看到的ReadAndExecute权限包括“列出文件夹内容”权限。 您可以使用FileSystemRights枚举中的相应标志来检查个别权限。 例如:

 if (fsar.FileSystemRights && FileSystemRights.ListDirectory) Console.WriteLine("Has List Directory permission");