因为之前工作需要,需要修改IIS下某网站文件和文件的权限:
string path = info.WebSitePath;
DirectoryInfo dirInfo = new DirectoryInfo(path);
DirectorySecurity dirSec = dirInfo.GetAccessControl();
IdentityReference user =
new NTAccount("IIS_IUSRS");
FileSystemAccessRule accRule
= new FileSystemAccessRule(user,FileSystemRights.FullControl,
AccessControlType.Allow);
dirSec.AddAccessRule(accRule);
dirInfo.SetAccessControl(dirSec);
string filePath = info.WebSitePath + @"\ServiceReferences.ClientConfig.xml";
FileInfo fileInfo = new FileInfo(filePath);
FileSecurity fileSec = fileInfo.GetAccessControl();
fileSec.AddAccessRule(accRule);
fileInfo.SetAccessControl(fileSec);