Csharp/C#教程:重复GetAccessRules,FileSystemAccessRule条目分享


重复GetAccessRules,FileSystemAccessRule条目

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

C:inetpubwwwrootAspInfoAccount BUILTINIIS_IUSRS : Allow : ReadAndExecute, Synchronize BUILTINIIS_IUSRS : Allow : -1610612736 NT SERVICETrustedInstaller : Allow : FullControl NT SERVICETrustedInstaller : 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枚举中的相应标志来检查个别权限。 例如:

上述就是C#学习教程:重复GetAccessRules,FileSystemAccessRule条目分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

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

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1039411.html

(0)
上一篇 2022年1月27日
下一篇 2022年1月27日

精彩推荐