文件夹权限

时间:2011-01-24 14:54:47

标签: c# windows file-permissions

为什么在浏览器属性窗口中浏览权限时,以下访问规则会显示为“特殊权限”?我希望它显示为正常的“修改”访问。

var di = new DirectoryInfo(ConfigDirectory);
DirectorySecurity security = di.GetAccessControl();
var rule = new FileSystemAccessRule(domainSid, FileSystemRights.Modify, AccessControlType.Allow);
security.AddAccessRule(rule);
di.SetAccessControl(security);

domainSid =域用户的SID。

  1. 如何创建规则,以便它在该文件夹中创建的所有文件继承?

1 个答案:

答案 0 :(得分:2)

请改用:

var di = new DirectoryInfo(ConfigDirectory);
DirectorySecurity security = di.GetAccessControl();
var rule = new FileSystemAccessRule(domainSid, FileSystemRights.Modify, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.None, AccessControlType.Allow);
security.AddAccessRule(rule);
security.SetAccessRule(rule);
di.SetAccessControl(security);

区别在于使用FileSystemAccessRule构造函数,它允许您指定继承和对security.SetAccessRule(rule);的调用