I am trying to give permission to C:\\Windows\\System32\\inetsrv\\config folder. But when I use the below code it throws exception "Attempted to perform an unauthorized operation."
string desktopFolderPath = @"C:\Windows\System32\inetsrv\config";
FileSystemAccessRule iis_iusrs = new FileSystemAccessRule("IIS_IUSRS",
FileSystemRights.FullControl,
InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
PropagationFlags.None,
AccessControlType.Allow);
FileSystemAccessRule networkService = new FileSystemAccessRule("NETWORK SERVICE",
FileSystemRights.FullControl,
InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
PropagationFlags.None,
AccessControlType.Allow);
System.IO.DirectoryInfo desktopFolderDirectory = new System.IO.DirectoryInfo(desktopFolderPath);
DirectorySecurity directorySecurity = null;
directorySecurity = desktopFolderDirectory.GetAccessControl(); -- **Exception**
directorySecurity.AddAccessRule(iis_iusrs);
directorySecurity.AddAccessRule(networkService);
desktopFolderDirectory.SetAccessControl(directorySecurity);
Please help if anyone can. Thanks in advance.
Go to the folder path Properties
and make sure it Read-only check box is unchecked.
This may be of some help: link
If it doesn't, then try sharing the folder.
By the way it is a system folder, It may not be accessible, so try hosting pages in
C:\\inetpub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.