How to set permissions on IIS6.0 virtual directory?
How to set permissions on IIS6.0 virtual directory like write/read etc by C# code and script (By command line)?
If you mean NTFS permissions then take a look at the following code:
/*
* 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);
For more info refer to:
DirectoryInfo.SetAccessControl Method (MSDN)
DirectorySecurity Class (MSDN)
FileSystemAccessRule Class (MSDN)
You could also use icacls.exe
:
icacls.exe d:\MyWebSite /grant bob:(CI)(OI)M
精彩评论