简体   繁体   English

DirectoryEntry IIS访问权限

[英]DirectoryEntry IIS access permission

I have one console application which list website binding in IIS 我有一个控制台应用程序,它列出了IIS中的网站绑定

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

I call this console application from ASP.NET via process 我通过进程从ASP.NET调用此控制台应用程序

var process = new Process {
   StartInfo = new ProcessStartInfo {
       FileName = "c:/app.exe",
       Arguments = "check",
       UseShellExecute = false,
       RedirectStandardOutput = true,
       CreateNoWindow = true
    }
};

Everything works fine on development machine under Widows 7 / IIS 7.5, but when i test on Windows 2012 / IIS 8 im getting "Access is denied" error. 在Widows 7 / IIS 7.5下的开发机器上一切正常,但是当我在Windows 2012 / IIS 8上测试时,我得到“访问被拒绝”错误。

Error log 错误日志

"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 Application pool identity is "ApplicationPoolIdentity" ps应用程序池标识是“ApplicationPoolIdentity”


I forget to mention, my console app works fine on my server when I run it from CMD 我忘了提一下,当我从CMD运行它时,我的控制台应用程序在我的服务器上工作正常

You need to give permission to the IUSR account to access and execute C:\\app.exe . 您需要授予IUSR帐户权限才能访问和执行C:\\app.exe This link should provide you with the necessary information to find the right account. 此链接应为您提供查找正确帐户所需的信息。

You have probably granted the permission to 'ApplicationPoolIdentity' rather than to the virtual account that actually corresponds to that Application Pool. 您可能已授予“ApplicationPoolIdentity”权限,而不是实际对应于该应用程序池的虚拟帐户。 Read through the Microsoft's description or search online for virtual identity IIS, etc. 阅读Microsoft的说明或在线搜索虚拟身份IIS等。

On your development machine, you probably have some sort of Full Admin rights, so it is not as restricted. 在您的开发计算机上,您可能拥有某种完全管理员权限,因此它不受限制。

If you still have problems after that, I would recommend replicating the error with a Process Monitor running, so you can see exactly what process is accessing which resource with which identity. 如果之后仍有问题,我建议在运行Process Monitor的情况下复制错误,这样您就可以确切地看到哪个进程正在访问哪个资源具有哪个标识。 However, I would recommend replicating the issue on your development machine rather than running Process Monitor on the production. 但是,我建议在开发计算机上复制该问题,而不是在生产中运行Process Monitor。 It takes a little bit of learning to be able to run it efficiently. 需要一点点学习才能有效地运行它。

在IIS 7/8中,打开或关闭控制面板 /程序和功能/打开Windows功能,并检查所有项目 :Web管理工具,(包括:IIS管理服务,II 6管理兼容性)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM