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