开发者

How to set permissions on IIS6.0 virtual directory?

开发者 https://www.devze.com 2023-01-17 23:29 出处:网络
开发者_C百科How to set permissions on IIS6.0 virtual directorylike write/read etc by C# code and script (By command line)?If you mean NTFS permissions then take a look at the following code:
开发者_C百科

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

0

精彩评论

暂无评论...
验证码 换一张
取 消