【问题标题】:How to assign access rights "Everyone" to a directory [duplicate]如何将访问权限“所有人”分配给目录[重复]
【发布时间】:2013-01-24 01:04:09
【问题描述】:

在我的 C# 小程序中,我在 Windows 上的目录文件夹“wwwroot”上为“Everyone”分配访问权限时遇到问题。 这是我的做法。

//I also try with 'S-1-1-0'/'Everyone' but it's the same result 
string userPermission = "Everyone"  ;

DirectoryInfo myDirRoot = new DirectoryInfo(myArmsUpdate.InstallationPath);
DirectorySecurity myDirectorySecurity = myDirRoot.GetAccessControl();
FileSystemAccessRule myPermission = new FileSystemAccessRule(userPermission , FileSystemRights.ReadAndExecute, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.InheritOnly, AccessControlType.Allow);

myDirectorySecurity.AddAccessRule(myPermission);
myDirRoot.SetAccessControl(myDirectorySecurity);

但是我仍然得到同样的错误:

System.Security.Principal.IdentityNotMappedException

【问题讨论】:

标签: c# .net security permissions windows-identity


【解决方案1】:

试试下面的,

DirectorySecurity sec = Directory.GetAccessControl(path);
        // Using this instead of the "Everyone" string means we work on non-English systems.
        SecurityIdentifier everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
        sec.AddAccessRule(new FileSystemAccessRule(everyone, FileSystemRights.Modify | FileSystemRights.Synchronize, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
        Directory.SetAccessControl(path, sec);

注意:您必须是管理员才能进行这项工作

【讨论】:

  • 完美!谢谢 。现在一切正常
  • 该代码看起来很像found here。如果您可以复制这样的代码,那么问题应该作为重复关闭。
猜你喜欢
  • 1970-01-01
  • 2018-10-24
  • 2022-10-20
  • 2010-12-27
  • 1970-01-01
  • 1970-01-01
  • 2010-10-16
  • 2012-12-21
  • 2013-09-18
相关资源
最近更新 更多