zoukankan      html  css  js  c++  java
  • C#修改文件的安全属性时报“没有可以设置的标志”

    遇到如图这样的问题:

    造成这样的错误原因是:

    原来的代码:

        void ModifyFileSecurityInfo(string filename, string username)
            {
    
                System.IO.FileInfo fileInfo = new FileInfo(filename);
                FileSecurity fs = fileInfo.GetAccessControl();
                fs.AddAccessRule(new FileSystemAccessRule(username, FileSystemRights.Modify, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
                fileInfo.SetAccessControl(fs);
            }

    改后的代码:

        void ModifyFileSecurityInfo(string filename, string username)
            {
    
                System.IO.FileInfo fileInfo = new FileInfo(filename);
                FileSecurity fs = fileInfo.GetAccessControl();
                fs.AddAccessRule(new FileSystemAccessRule(username, FileSystemRights.Modify, InheritanceFlags.None, PropagationFlags.None, AccessControlType.Allow));
                fileInfo.SetAccessControl(fs);
            }

    InheritanceFlags的解释是:指定访问控制项(ACE)的继承语义。

    有三个枚举:

    None 子对象未继承ACE

    ContainerInherit 由容器子对象继承   我理解为“文件夹”可以指定该标志

    ObjectInherit由子叶对象继承    我理解为“文件”可以指定该标志

  • 相关阅读:
    【设计模式】策略模式
    【设计模式】模板方法模式
    【C++】《Effective C++》第五章
    【C++】《Effective C++》第四章
    free命令详解(内存)
    top命令详解(动态进程)
    ps命令详解(静态进程)
    SpringBoot_集成Redis
    SpringBoot_热部署插件
    SpringBoot_实现RESTfull API
  • 原文地址:https://www.cnblogs.com/langu/p/2827424.html
Copyright © 2011-2022 走看看