Quantcast
Channel: Installation and Setup
Viewing all articles
Browse latest Browse all 631

Is there a programmatic way to set Write permissions to my app's folders?

$
0
0

Every time I install my web app, I have to manually set Write permissions to two folders.  I got to thinking that the global "Application_Start" method could do this for me automatically.  Here's my initial attempt to do this with the root-level "Logs" folder:

  private void SetRequiredFolderWritePermissions()
  {
    string rootPath = Server.MapPath("~");
    DirectoryInfo info = new DirectoryInfo(rootPath + "Logs");
    //WindowsIdentity iisIUsrs = new WindowsIdentity("IIS_IUSRS");
    DirectorySecurity ds = info.GetAccessControl();
    ds.AddAccessRule(new FileSystemAccessRule("IIS_IUSRS", FileSystemRights.Write, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.None, AccessControlType.Allow));
    info.SetAccessControl(ds);
  }

It doesn't cause an error but when I check whether "IIS_IUSRS" has Write privileges for the "Logs" folder, it does not.

Is there a correct way to do this?

Robert


Viewing all articles
Browse latest Browse all 631

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>