Tôi phải gán quyền trên thư mục và thư mục con cũng như tệp của chương trình bằng C# .NET. Tôi làm như sau:Chỉ định quyền truy cập danh sách điều khiển truy cập (ACL) theo cách lập trình cho 'thư mục, thư mục con và tệp'
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)
{
//...
}
Nó chỉ định quyền trên thư mục 'C: \ ROOT' của tôi. Nhưng nó chỉ gán quyền cho các Thư mục con và Tập tin nhưng không được phép cho thư mục 'ROOT'.
H: Làm cách nào để xác định trường hợp FileSystemAccessRule
để gán quyền cho thư mục ROOT, Thư mục con và tệp?
@Kibria Tôi rất tò mò. Trợ giúp này có hữu ích không? –
có, cảm ơn! – Kibria