首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >C#文件/目录权限

C#文件/目录权限
EN

Stack Overflow用户
提问于 2009-01-09 21:45:18
回答 4查看 28.8K关注 0票数 16

我正在编写一个应用程序来管理用户对文件的访问。简而言之,我必须使用目录和文件权限来完成此任务。我们廉价的CEO没有文件管理系统...

不管怎样..。除了用户可以查看目录中的哪些文件,但实际上看不到文件的内容之外,我已经让一切正常工作了。(文件中可能包含敏感的HR数据。)

我尝试了FileSystemRights.ListDirectory,但这似乎也将ReadData设置为true (忽略MS文档)。我关闭了ReadData (读取文件的能力),突然再次无法访问该目录。这两者似乎是联系在一起的。

有什么想法可以设置哪些权限来实现这一点?

我当前的代码是:

代码语言:javascript
运行
复制
SetSecurity(pth, usr, FileSystemRights.ListDirectory, AccessControlType.Allow);

...

public void SetSecurity(string dirName, string account,
    FileSystemRights rights, AccessControlType controlType)
{
    // Get a FileSecurity object that represents the
    // current security settings.
    DirectorySecurity dSecurity = Directory.GetAccessControl(dirName);

    dSecurity.AddAccessRule(new FileSystemAccessRule(account, rights, controlType));

    // Set the new access settings.
    Directory.SetAccessControl(dirName, dSecurity);
}

谢谢。

--Jerry

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/429864

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档