如何在IIS6.0虚拟目录上设置权限?

时间:2010-09-27 13:40:01

标签: iis-6

如何通过C#代码和脚本(通过命令行)设置IIS6.0虚拟目录的权限,如写/读等?

1 个答案:

答案 0 :(得分:1)

如果您的意思是NTFS权限,请查看以下代码:

/*
 * Set Modify permission on D:\MyWebSite and all children
*/

string path = @"D:\MyWebSite";
string userID = "BOB";

FileSystemRights rights = FileSystemRights.Modify;
InheritanceFlags inheritanceflags = 
          InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit;

DirectorySecurity acls = Directory.GetAccessControl(path);
FileSystemAccessRule acl =
   new FileSystemAccessRule(
          new NTAccount(userID),
          rights,
          inheritanceFlags,
          PropagationFlags.None,
          AccessControlType.Allow);
acls.AddAccessRule(acl);
Directory.SetAccessControl(path, acls);

有关详细信息,请参阅:

  

DirectoryInfo.SetAccessControl Method (MSDN)

     

DirectorySecurity Class (MSDN)

     

FileSystemAccessRule Class (MSDN)

您也可以使用icacls.exe

icacls.exe d:\MyWebSite /grant bob:(CI)(OI)M