Programmatically Adding Permissions to a Folder

后端 未结 1 412
北荒
北荒 2021-02-07 06:38

I have an issue where I need to add give access to a folder for all authenticated users to store application related settings. I have found that this can be done with the below

相关标签:
1条回答
  • 2021-02-07 07:15

    I'd suggest you use the Well Known SID list (see http://support.microsoft.com/kb/243330). Authenticated User is always SID: S-1-5-11. If you use that, it ought to be language agnostic (but I've not tested).

    Create a SecurityIdentifier and use that instead:

    var sid = new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null); 
    
    Security.AddAccessRule(
       new FileSystemAccessRule(
           sid,
           FileSystemRights.Modify,
           InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
           PropagationFlags.None,
           AccessControlType.Allow));
    
    0 讨论(0)
提交回复
热议问题