DirectoryEntry IIS访问权限

Nov*_*ato 5 c# windows security iis iis-8

我有一个控制台应用程序,该应用程序列出了IIS中的网站绑定

using (var directoryEntry = new DirectoryEntry("IIS://localhost/w3svc/" + GetWebSiteId())) {
    var bindings = directoryEntry.Properties["ServerBindings"]; 
}
Run Code Online (Sandbox Code Playgroud)

我通过过程从ASP.NET调用此控制台应用程序

var process = new Process {
   StartInfo = new ProcessStartInfo {
       FileName = "c:/app.exe",
       Arguments = "check",
       UseShellExecute = false,
       RedirectStandardOutput = true,
       CreateNoWindow = true
    }
};
Run Code Online (Sandbox Code Playgroud)

在Widows 7 / IIS 7.5下的开发机上,一切正常,但是当我在Windows 2012 / IIS 8上进行测试时,我收到“拒绝访问”错误。

错误记录

"System.Runtime.InteropServices.COMException (0x80070005): Access is denied.
at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
at System.DirectoryServices.DirectoryEntry.Bind()
at System.DirectoryServices.DirectoryEntry.get_IsContainer()
at System.DirectoryServices.DirectoryEntries.ChildEnumerator..ctor(DirectoryEntry container)
at System.DirectoryServices.DirectoryEntries.GetEnumerator()
at IISSubdomainManagement.Program.GetWebSiteId()
at IISSubdomainManagement.Program.TotalBindings()
at IISSubdomainManagement.Program.Main(String[] args)"
Run Code Online (Sandbox Code Playgroud)

ps应用程序池标识为“ ApplicationPoolIdentity”


我忘了提一下,当我从CMD运行它时,我的控制台应用程序可以在服务器上正常运行

ody*_*jii 2

您需要授予 IUSR 帐户访问和执行的权限C:\app.exe此链接应为您提供找到正确帐户所需的信息。