微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – 重复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 + "<br/>");
    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 + "<br/>");
    }
  }
}

解决方法

您将获得继承的规则和明确设置在该文件夹上的规则的单独的规则条目.根据每个规则的传播设置,也有差异.例如,您可以拥有一组设置为传播到子文件夹的权限,以及与文件夹中的文件不同的一组权限.您的代码还会在您希望访问权限(DACL)的文件夹上获得审核规则(SACL).

尝试这个:

protected void directoryInfo()
{
  var di = new DirectoryInfo(Server.MapPath("/"));
  foreach (DirectoryInfo dir in di.GetDirectories())
  {
    Response.Write(dir.FullName + "<br/>");
    DirectorySecurity ds = dir.GetAccessControl(AccessControlSections.Access);
    foreach (FileSystemAccessRule fsar in ds.GetAccessRules(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 + "<br/>");
    }
  }
}

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

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

原文地址:https://www.jb51.cc/csharp/92742.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐