[C#] 更改檔案夾套入 IIS APPPOOL\ 權限
2020-11-03
最近有一個需求,要透過程式套入檔案夾套入 iis apppool\test2 的權限
程式碼也很簡單
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void SetDirectoryIISAccessRule(string path, string ruleName) | |
{ | |
var pathDir = new DirectoryInfo(path); | |
var acl = pathDir.GetAccessControl(); | |
string acc = $"IIS APPPOOL\\" + ruleName; | |
acl.AddAccessRule(new FileSystemAccessRule(acc, FileSystemRights.Modify, AccessControlType.Allow)); | |
acl.AddAccessRule(new FileSystemAccessRule(acc, FileSystemRights.Modify, InheritanceFlags.ContainerInherit, PropagationFlags.InheritOnly, AccessControlType.Allow)); | |
acl.AddAccessRule(new FileSystemAccessRule(acc, FileSystemRights.Modify, InheritanceFlags.ObjectInherit, PropagationFlags.InheritOnly, AccessControlType.Allow)); | |
pathDir.SetAccessControl(acl); | |
} | |
//call : SetDirectoryIISAccessRule(@"C:\Users\no2don\Desktop\PUBLISH\TEST1_WEB", "test2"); | |
直接呼叫就好了,這邊就不贅述了,筆記一下,之後要用到就可以直接CP