There is such code. On a call dSecurity.ModifyAccessRule appears System.Security.Principal.IdentityNotMappedException
What not so?
Code:public void AddDirectorySecurity(string FileName, string Account, FileSystemRights Rights, AccessControlType ControlType) { // Create a new DirectoryInfo object. DirectoryInfo dInfo = new DirectoryInfo(FileName); // Get a DirectorySecurity object that represents the // current security settings. DirectorySecurity dSecurity = dInfo.GetAccessControl(); FileSystemAccessRule fsAccess = new FileSystemAccessRule( Account, Rights, InheritanceFlags.None, PropagationFlags.NoPropagateInherit, ControlType); bool allOK; dSecurity.ModifyAccessRule(AccessControlModification.Add, fsAccess, out allOK); if (!allOK) throw new ApplicationException("Unable to add access rule to directory," + FileName + ", for " + Account); // Устанавливаем правила наследвания доступа FileSystemAccessRule inheritanceRule = new FileSystemAccessRule( Account, Rights, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.InheritOnly, ControlType); dSecurity.ModifyAccessRule(AccessControlModification.Add, inheritanceRule, out allOK); if (!allOK) throw new ApplicationException("Unable to add inheritance rule to directory," + FileName + ", for " + Account); // Устанавливаем новые параметры доступа. dInfo.SetAccessControl(dSecurity); }




Reply With Quote
