C#设置文件夹权限
设置用户"NETWORK SERVICE"具有对文件夹的读取权限。
1 System.Security.AccessControl.DirectorySecurity fSec;
2
3 string path = "D:\\Test";
4 fSec = new DirectorySecurity();
5 //设置权限的应用为文件夹本身、子文件夹及文件
6 //所以需要InheritanceFlags.ContainerInherit 或 InheritanceFlags.ObjectInherit
7 fSec.AddAccessRule(new FileSystemAccessRule("NETWORK SERVICE", FileSystemRights.Read, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
8 System.IO.Directory.SetAccessControl(path, fSec);
9
2
3 string path = "D:\\Test";
4 fSec = new DirectorySecurity();
5 //设置权限的应用为文件夹本身、子文件夹及文件
6 //所以需要InheritanceFlags.ContainerInherit 或 InheritanceFlags.ObjectInherit
7 fSec.AddAccessRule(new FileSystemAccessRule("NETWORK SERVICE", FileSystemRights.Read, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
8 System.IO.Directory.SetAccessControl(path, fSec);
9
顺便提一下,NETWORK SERVICE是IIS6.0的默认用户,而ASPNET是IIS5.0的默认用户。
有一个问题:NETWORK SERVICE在Window2003的电脑管理/用户里面并没有这个用户。