惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
V
Visual Studio Blog
有赞技术团队
有赞技术团队
T
Tailwind CSS Blog
B
Blog
I
InfoQ
博客园 - 三生石上(FineUI控件)
阮一峰的网络日志
阮一峰的网络日志
F
Fortinet All Blogs
H
Help Net Security
博客园 - Franky
宝玉的分享
宝玉的分享
博客园 - 司徒正美
C
Check Point Blog
G
Google Developers Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Jina AI
Jina AI
T
The Blog of Author Tim Ferriss
MongoDB | Blog
MongoDB | Blog
云风的 BLOG
云风的 BLOG
A
About on SuperTechFans
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
IT之家
IT之家

博客园 - chy710

隐藏ASP.NET站点的head信息(Server/X-Powered-By/X-Aspnet-Version) Jenkins持续集成 入门实践 Docker入门实践 程序员该有的职业素养 ubuntu sudoers配置错误 MVC Json方法里的一个坑 日志分析工具 Log Parser 压力测试记录 Winscp使用sudo user登录 Linux下通过NFS共享文件夹 Jexus 5.4.6 on CentOS 6.6 数据传输过程的安全考虑 RSA密钥的跨平台通用 MongoDB中的字段类型Id Nginx运行Mono Web (ASP.NET) CentOS升级MySQL到5.5 写给自己看的Linux运维基础(四) - python环境 Python模拟HTTP Post上传文件 Navicat for MySQL的服务器连接管理
C#修改文件权限
chy710 · 2013-09-11 · via 博客园 - chy710

用户名的格式为: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));