如何设置对目录的完全控制?

smw*_*dia 8 .net c#

我使用以下简单代码将完全控制添加到目录,但它不起作用.

        String dir_name = @"folder_full_path";
        DirectorySecurity dir_security = Directory.GetAccessControl(dir_name);
        FileSystemAccessRule access_rule = new FileSystemAccessRule(@"AccountName",
            FileSystemRights.FullControl, AccessControlType.Allow);
        dSecurity.AddAccessRule(access_rule);
        Directory.SetAccessControl(dir_name, dir_security);
Run Code Online (Sandbox Code Playgroud)

但是此代码仅为目标文件夹设置了特殊权限.此代码与MSDN示例几乎相同.我正在摸索着一个合理的解释......希望有人可以对我有所了解.

非常感谢.

Gam*_*ing 13

在对原始ACL规则进行了一些逆向工程之后,我使用了以下代码:

IdentityReference everybodyIdentity = new SecurityIdentifier(WellKnownSidType.WorldSid, null);

FileSystemAccessRule rule = new FileSystemAccessRule(
    everybodyIdentity,
    FileSystemRights.FullControl, 
    InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
    PropagationFlags.None,
    AccessControlType.Allow);
Run Code Online (Sandbox Code Playgroud)

可以帮助任何更多的访客:)


小智 -4

:) 回转。

  • 建立一个目录。

  • 分配权限。

  • 阅读 DirectorySecurity ACL 并在调试器中检查它的外观;)

瞧。