用户名的格式为:Local MachineName\AccountName

机器名可通过System.Environment.MachineName获取。

 

获取一个文件的权限(帐号)列表

FileSecurity fsec = new FileInfo(path).GetAccessControl();
AuthorizationRuleCollection ar= fsec.GetAccessRules(truetruetypeof(System.Security.Principal.NTAccount));
foreach (AuthorizationRule r in ar)
    r.IdentityReference.Value;


给一个文件赋于IIS帐号的写权限

FileSecurity fsec = new FileInfo(path).GetAccessControl();
fsec.SetAccessRule(new FileSystemAccessRule(@"WEB-01\IIS_IUSRS", FileSystemRights.Write, AccessControlType.Allow));

 

设置文件夹的权限

DirectoryInfo dinfo = new DirectoryInfo(path);
DirectorySecurity dsecurity = dinfo.GetAccessControl();
dsecurity.AddAccessRule(new FileSystemAccessRule(@"WEB-01\IIS_IUSRS", FileSystemRights.Write, AccessControlType.Allow));

 

相关文章:

  • 2021-06-30
  • 2021-11-11
  • 2021-12-19
  • 2022-02-16
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-24
  • 2021-09-15
  • 2021-08-17
  • 2021-05-07
  • 2021-12-31
  • 2021-12-17
  • 2021-08-09
相关资源
相似解决方案