title: How to assign IIS 7.5 file system access permissions on a Domain Controller?
body: <p>I have a somewhat unusual situation.</p>
  
  <p>I am dealing with IIS 7.5 installed on a Windows Server 2008 R2 Domain Controller machine.</p>
  
  <p>I am trying to write a C# program that installs my web application on that IIS. Everything works OK, except the moment when I need to assign access permissions for the Application Pool to the folder where the web app is installed. </p>
  
  <p>After having done some research I found that I need to assign access for the following user account:</p>
  
  <blockquote>
    <p>IIS AppPool\[AppPoolName]</p>
  </blockquote>
  
  <p>So I came up with this code:</p>
  
  <pre><code>setFolderPermissions(@"C:\inetpub\www_test1",
      @"IIS AppPool\" + strAppPoolName,
      System.Security.AccessControl.FileSystemRights.Read | System.Security.AccessControl.FileSystemRights.ListDirectory,
      System.Security.AccessControl.AccessControlType.Allow);
  
  public static string setFolderPermissions(string strFolderPath, string sUserName, FileSystemRights rights, AccessControlType access)
  {
      DirectoryInfo info = new DirectoryInfo(strFolderPath);
  
      DirectorySecurity ds = info.GetAccessControl();
      ds.AddAccessRule(new FileSystemAccessRule(sUserName,
                          rights,
                          InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit,
                          PropagationFlags.None,
                          access));
  
      info.SetAccessControl(ds);
  }
  </code></pre>
  
  <p>The method above works except when it is useed on a Domain Controller. It throws this exception:</p>
  
  <blockquote>
    <p><em>Some or all identity references could not be translated.</em></p>
  </blockquote>
  
  <p>And the only way how I can assign those required permissions is by doing this <em>manually</em> from a command line:</p>
  
  <pre><code>C:\Users\Administrator&gt;icacls "C:\inetpub\www_test1" /grant "IIS AppPool\MyAppsoolName":(CI)(OI)(M)
  </code></pre>
  
  <p>Any idea how to do this <code>icacls</code> stuff with C#?</p>