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

  • 相关阅读:
    004---基于TCP的套接字
    003---socket介绍
    002---tcp/ip五层详解
    001---C/S架构
    008---re正则模块
    007---logging日志模块
    006---hashlib模块
    005---json & pickle
    004---os & sys
    22.解决 eclipse 与 AS 共用 SDK 导致 eclipse ADT 无法使用的问题
  • 原文地址:https://www.cnblogs.com/yonsy/p/2652636.html
Copyright © 2011-2022 走看看