title: How to work with ACL in .NET Core 2?
body: <p>ASP.NET Core MVC 2</p>
  
  <p>My web-application will be hosted on IIS 8 (Windows Server 2012 R2). I need to work with ACL of some files and directories. I attached <a href="https://www.nuget.org/packages/System.IO.FileSystem.AccessControl/" rel="noreferrer">System.IO.FileSystem.AccessControl</a> package to my project, but I have some problems still... Also I see some info about this theme on Microsoft site <a href="https://docs.microsoft.com/en-us/dotnet/api/system.security.accesscontrol?view=netframework-4.7.2" rel="noreferrer">here</a>. But I don't see the code examples.</p>
  
  <p>I know how to work with ACL through .NET Framework but I don't know how to do it in .NET Core 2. This is my code with my questions (I commented code which works in .NET Framework but doesn't work in .NET Core 2):</p>
  
  <pre><code>using System;
  using System.IO;
  
  // NuGet package: System.IO.FileSystem.AccessControl
  using System.Security.AccessControl;
  using System.Security.Principal;
  
  namespace ACL_Sandbox
  {
      class Program
      {
          static void Main(string[] args)
          {
              try
              {
                  var fileName = "data.txt";
                  File.Create(fileName);
  
                  // How to get the FileSecurity of the file in .NET Core 2?
                  FileSecurity sec = null; // File.GetAccessControl(true,true,typeof(NTAccount));
  
                  AuthorizationRuleCollection rules = sec.GetAccessRules(true, true, null);
  
                  foreach (FileSystemAccessRule rule in rules)
                  {
                      Console.WriteLine("AccessControlType: {0}", rule.AccessControlType);
                      Console.WriteLine("FileSystemRights: {0}", rule.FileSystemRights);
                      Console.WriteLine("IdentityReference.Value: {0}", rule.IdentityReference.Value);
                      Console.WriteLine("\n=======\n");
                  }
  
                  var sid = new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null);
                  string usersAccount = sid.Translate(typeof(NTAccount)).ToString();
                  FileSystemAccessRule newRule = new FileSystemAccessRule(usersAccount, 
                      FileSystemRights.ExecuteFile, AccessControlType.Allow);
                  sec.AddAccessRule(newRule);
  
                  // How to set the access rule for the file in .NET Core 2?
                  // File.SetAccessRule(sec);
  
              }
              catch (Exception ex)
              {
                  Console.WriteLine("Exception: {0}", ex.Message);
              }
  
              Console.WriteLine("Press any key for exit...");
              Console.ReadKey();
          }
      }
  }
  </code></pre>
  
  <p>JetBrains Rider IDE for the class <code>FileSecurity</code> shows me such code sources:</p>
  
  <pre><code>// Decompiled with JetBrains decompiler
  // Type: System.Security.AccessControl.FileSecurity
  // Assembly: System.IO.FileSystem.AccessControl, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
  // MVID: 95551778-530B-4B9F-8EB6-1D54F85B3C4B
  // Assembly location: /usr/share/dotnet/shared/Microsoft.NETCore.App/2.0.5/System.IO.FileSystem.AccessControl.dll
  
  namespace System.Security.AccessControl
  {
    [SecurityCritical]
    public sealed class FileSecurity : FileSystemSecurity
    {
      public FileSecurity()
      {
        throw new PlatformNotSupportedException(SR.PlatformNotSupported_AccessControl);
      }
  
      public FileSecurity(string fileName, AccessControlSections includeSections)
      {
        throw new PlatformNotSupportedException(SR.PlatformNotSupported_AccessControl);
      }
    }
  }
  </code></pre>
  
  <p>This is not encouraging ...</p>
  
  <p>Is it possible to work with ACL in .NET Core 2? 
  If "yes" then how can I get the the FileSecurity of the file in .NET Core 2? 
  Also, if "yes" then how can I set the access rule for the file in .NET Core 2?</p>