【问题标题】:DirectoryEntry IIS access permissionDirectoryEntry IIS 访问权限
【发布时间】:2013-01-15 22:31:17
【问题描述】:

我有一个控制台应用程序,它列出了 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)"

p.s 应用程序池标识为“ApplicationPoolIdentity”


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

【问题讨论】:

  • 我以前有过这个,如果我记得,问题是它在哪里寻找 AD 服务器或凭据没有正确的权限。这很烦人,因为它在本地运行良好

标签: c# windows security iis iis-8


【解决方案1】:

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

【讨论】:

  • IUSR 和 IIS_IUSRS 对 app.exe 有完全的安全控制,但仍然不起作用
  • 我可以确认您在 IIS_IUSRS 无权访问时得到的 COMException 是 System.DirectoryServices.DirectoryServicesCOMException (0x80072020): An operations error occurred.(而不是 Access denied
【解决方案2】:

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

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

如果在那之后您仍然有问题,我建议您通过运行Process Monitor 来复制错误,这样您就可以准确地看到哪个进程正在使用哪个身份访问哪个资源。但是,我建议在您的开发机器上复制该问题,而不是在生产中运行 Process Monitor。需要一点点学习才能有效地运行它。

【讨论】:

  • 完成,我将我的应用程序池创建的虚拟身份添加为 app.exe 的完全安全权限,但仍然出现该错误...
  • 当我选择“LocalSystem”作为应用程序池标识时,一切正常,但为什么我不能作为 ApplicationPoolIdentity
  • LocalSystem 是一个真实的身份,一个是一个特例。我更新了主要评论,添加了有关下一步故障排除的其他建议。
【解决方案3】:

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

【讨论】:

    【解决方案4】:
    猜你喜欢
    • 1970-01-01
    • 2012-07-12
    • 2010-10-14
    • 2012-07-23
    • 1970-01-01
    • 2011-07-23
    • 2013-12-21
    • 2023-03-29
    • 2011-08-13
    相关资源
    最近更新 更多