using System.Security.AccessControl;

//设置myFloder文件夹的iis访问权限
                string userAccount = @"IIS_IUSRS";
                string filePath = @"C:\inetpub\myFloder";
                DirectorySecurity dSecurity = Directory.GetAccessControl(filePath,
                        AccessControlSections.All);

dSecurity.AddAccessRule(new FileSystemAccessRule(userAccount,
                                       FileSystemRights.FullControl,
                                       InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
                                       PropagationFlags.None,
                                       AccessControlType.Allow));
                Directory.SetAccessControl(filePath, dSecurity);

04-28 16:53