2013-01-15 69 views
4

我有一个控制台应用程序,列表网站在IIS结合的DirectoryEntry 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上测试时出现“Access is denied”错误。

错误日志

"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

+0

我已经收到了这一个,如果我还记得,这个问题是要么在那里寻找AD服务器或凭据别没有正确的权限。这很烦人,因为它在本地工作正常 – Brian

回答

2
运行

您需要授予IUSR帐户权限才能访问并执行C:\app.exeThis link应该为您提供必要的信息以找到正确的帐户。

+1

IUSR和IIS_IUSRS具有完整的app.exe安全控制,但仍然不工作 –

+0

我可以确认当IIS_IUSRS没有访问时得到的COMException是System.DirectoryServices.DirectoryServicesCOMException(0x80072020) :发生操作错误.'(而不是'访问被拒绝') – codeMonkey

1

您可能已授予“ApplicationPoolIdentity”权限,而不授予实际与该应用程序池对应的虚拟帐户。通读Microsoft's description或在线搜索虚拟身份IIS等。

在您的开发机器上,您可能拥有某种完全管理权限,因此它不受限制。

如果之后仍然存在问题,我建议您将错误复制到Process Monitor正在运行,以便您可以确切了解哪个进程正在访问哪个资源具有哪个身份。但是,我建议在开发机器上复制问题,而不是在生产环境中运行Process Monitor。它需要一点点的学习才能够有效地运行它。

+0

完成后,我将我的应用程序池创建的虚拟身份添加为app.exe的完全安全权限,但仍然出现错误... –

+0

当我选择“LocalSystem”作为应用程序池标识,一切正常,但为什么我不能作为ApplicationPoolIdentity –

+0

LocalSystem是一个真实身份,一个是特例。我更新了主要评论,并提供了关于下一步故障排除的其他建议。 –

1

在IIS 7/8去控制面板 /程序和功能/启用Windows功能打开或关闭,并检查所有项目来源:网络枭雄工具,(它的包括:IIS枭雄服务,II 6枭雄兼容性)