Programowo przypisz uprawnienia listy kontroli dostępu (ACL) do „tego folderu, podfolderów i plików”
Muszę przypisać uprawnienia do folderu i jego folderu podrzędnego i plików programowo za pomocą C # .NET. Robię to jak poniżej:
var rootDic = @"C:\ROOT";
var identity = "NETWORK SERVICE"; //The name of a user account.
try
{
var accessRule = new FileSystemAccessRule(identity,
fileSystemRights: FileSystemRights.Modify,
inheritanceFlags: InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
propagationFlags: PropagationFlags.InheritOnly,
type: AccessControlType.Allow);
var directoryInfo = new DirectoryInfo(rootDic);
// Get a DirectorySecurity object that represents the current security settings.
DirectorySecurity dSecurity = directoryInfo.GetAccessControl();
// Add the FileSystemAccessRule to the security settings.
dSecurity.AddAccessRule(accessRule);
// Set the new access settings.
directoryInfo.SetAccessControl(dSecurity);
}
catch (Exception ex)
{
//...
}
Przypisuje uprawnienia do mojego folderu „C: ROOT”. Ale przydziela uprawnienia tylko do podfolderów i plików, ale nie do folderu „ROOT”.
P: Jak mogę zdefiniowaćFileSystemAccessRule
instancja przypisująca uprawnienia do folderu ROOT, podfolderów i plików?