我有一个控制台应用程序,它列出了 IIS 中的网站绑定
using (var directoryEntry = new DirectoryEntry("IIS://localhost/w3svc/" + GetWebSiteId())) {
var bindings = directoryEntry.Properties["ServerBindings"];
}
我通过进程从 ASP.NET 调用此控制台应用程序
var process = new Process {
StartInfo = new ProcessStartInfo {
FileName = "c:/app.exe",
Arguments = "check",
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};
在 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)"
ps 应用程序池标识为“ApplicationPoolIdentity”
我忘了提一下,当我从 CMD 运行控制台应用程序时,它在我的服务器上运行良好