I am trying to progamrtaiclly allow write access to ASPNET account on a directory. I am using the following code to do this: (Please note that I want the "write access allowed" for ASPNET to be propagated to the child objects as well:
static void Main(string[] args)
{
FileSecurity fileSecurity;
fileSecurity = new FileSecurity();
fileSecurity.SetAccessRuleProtection(true, false);
fileSecurity.AddAccessRule(new FileSystemAccessRule("ASPNET",FileSystemRights.Write,InheritanceFlags.ObjectInherit|InheritanceFlags.ContainerInherit,PropagationFlags.InheritOnly,AccessControlType.Allow));
File.SetAccessControl("C:\\TestDir1", fileSecurity);
}
This code is resulting in the exception: "No flags can be set.\r\nParameter name: inheritanceFlags"
What could be wrong?