zoukankan      html  css  js  c++  java
  • 设置服务器文件的访问权限


            /// <summary>
            /// 为创建的临时文件分配权限
            /// </summary>
            /// <param name="pathname">文件路径</param>
            /// 如:D:\aqi\Aqioo.Apps\Aqioo.Apps\Aqioo.Apps.Web\xml\constellation.xml
            /// <param name="username">用户名(一般用:ASPNET)</param>
            /// <param name="power">权限</param>
            /// <remarks>SKY 2007-8-6</remarks>
            public static void AddpathPower(string pathname, string username, string power)
            {

                DirectoryInfo dirinfo = new DirectoryInfo(pathname);

                if ((dirinfo.Attributes & FileAttributes.ReadOnly) != 0)
                {
                    dirinfo.Attributes = FileAttributes.Normal;
                }

                //取得访问控制列表
                DirectorySecurity dirsecurity = dirinfo.GetAccessControl();

                switch (power)
                {
                    case "FullControl":
                        dirsecurity.AddAccessRule(new FileSystemAccessRule(username, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit, PropagationFlags.InheritOnly, AccessControlType.Allow));
                        break;
                    case "ReadOnly":
                        dirsecurity.AddAccessRule(new FileSystemAccessRule(username, FileSystemRights.Read, AccessControlType.Allow));
                        break;
                    case "Write":
                        dirsecurity.AddAccessRule(new FileSystemAccessRule(username, FileSystemRights.Write, AccessControlType.Allow));
                        break;
                    case "Modify":
                        dirsecurity.AddAccessRule(new FileSystemAccessRule(username, FileSystemRights.Modify, AccessControlType.Allow));
                        break;
                }
            }

  • 相关阅读:
    cf------(round)#1 C. Ancient Berland Circus(几何)
    cf------(round)#1 B. Spreadsheets(模拟)
    grep 精确匹配
    解决 service iptables save 报错 please try to use systemctl
    kubernetes 亲和性调度详解
    免费好用的SSH手机客户端
    axios和drf结合的增删改查
    CDH 部署 Hadoop:5.开始安装
    OpenNebula概述
    Python 3.x 引入了函数注释
  • 原文地址:https://www.cnblogs.com/yonsy/p/2652636.html
Copyright © 2011-2022 走看看