• 设置服务器文件的访问权限



            /// <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;
                }
            }

  • 相关阅读:
    S3C2440实现dm9000网卡驱动程序移植
    IMX257虚拟网卡vnet驱动程序
    ram_flash驱动
    S3C2440 nor_flash驱动程序
    Java 打印* 三角形
    Java系列学习说明
    java案例1,打印hello java
    zabbixproxy安装
    python鉴黄程序
    mssql发布订阅事项
  • 原文地址:https://www.cnblogs.com/yonsy/p/2652636.html
Copyright © 2020-2023  润新知