• 使用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);
            }
  • 相关阅读:
    bzoj 3155: Preprefix sum
    bzoj 1854: [Scoi2010]游戏
    UVA1608 不无聊的序列 Non-boring sequences
    UVA1747 【Swap Space】
    Luogu P5550 Chino的数列
    bzoj 1799: [Ahoi2009]self 同类分布
    bzoj 1054: [HAOI2008]移动玩具
    MATLAB工具箱,应用程序,软件和资源的精选清单
    论文格式排版Issue及解决办法
    《将博客搬至CSDN》
  • 原文地址:https://www.cnblogs.com/wjx-blog/p/13915458.html
Copyright © 2020-2023  润新知