zoukankan      html  css  js  c++  java
  • 使用c#程序 添加iis网站目录的用户权限

    1、放一个按钮,在单击事件里选择一个文件目录,如下:

            private void Button_Click(object sender, RoutedEventArgs e)
            {
                CommonOpenFileDialog dialog = new CommonOpenFileDialog();
                dialog.IsFolderPicker = true;//设置为选择文件夹
                if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
                {
                    this.txtPath.Text = dialog.FileName;
                }
                AddSecurityControll2Folder(this.txtPath.Text);
    
                MessageBox.Show("添加IIS网站目录权限成功!");
            }

    2、执行目录权限修改的方法,方法如下:

    static void AddSecurityControll2Folder(string dirPath)
            {
                DirectoryInfo dir = new DirectoryInfo(dirPath);
                //获得该文件夹的所有访问权限
                System.Security.AccessControl.DirectorySecurity dirSecurity = dir.GetAccessControl(AccessControlSections.All);
                //设定文件ACL继承
                InheritanceFlags inherits = InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit;
    
                FileSystemAccessRule IIS_IUSRS_FileSystemAccessRule = new FileSystemAccessRule("IIS_IUSRS", FileSystemRights.FullControl, inherits, PropagationFlags.None, AccessControlType.Allow);
                FileSystemAccessRule IUSR_FileSystemAccessRule = new FileSystemAccessRule("IUSR", FileSystemRights.FullControl, inherits, PropagationFlags.None, AccessControlType.Allow);
                bool isModified = false;
    
                dirSecurity.ModifyAccessRule(AccessControlModification.Add, IIS_IUSRS_FileSystemAccessRule, out isModified);
                dirSecurity.ModifyAccessRule(AccessControlModification.Add, IUSR_FileSystemAccessRule, out isModified);
                dir.SetAccessControl(dirSecurity);
            }
  • 相关阅读:
    (7)排序之归并排序
    (5)排序之简单选择排序
    (4)排序之希尔排序
    (3)排序之直接插入排序
    (2)排序之快速排序
    (1)排序之冒泡排序
    Python学习
    centos下docker网络桥接
    docker下搭建gitlab
    centos版本7以上网卡名修改
  • 原文地址:https://www.cnblogs.com/wjx-blog/p/13915458.html
Copyright © 2011-2022 走看看