windows - 为什么使用IIS7.5的Microsoft.Web.Management.dll只能在64位进程中使用?

标签 windows iis 64-bit iis-7.5

我正在编写一些代码以允许用户远程管理 IIS7。在引擎盖下,这将授权规则添加到 c:\windows\system32\inetsrv\config\administration.config在以下配置部分下:

system.webServer/management/authorization/authorizationRules

我正在使用 Microsoft.Web.Administration程序集和命名空间的代码类似于以下内容:

using Microsoft.Web.Management.Server;
...
ManagementAuthorization.Grant("MySiteUser, "My Web Site", false);

如果在 32 位进程中运行此代码会抛出异常,如果构建为 64 位进程则运行良好:

System.Runtime.InteropServices.COMException was unhandled
  Message=Filename: \\?\C:\Windows\system32\inetsrv\config\administration.config
Error: The configuration section 'system.webServer/management/authorization' cannot be read because it is missing a section declaration`

However other server management tasks performed using the Microsoft.Web.Administration assembly and namespace work just fine in a 32 bit process, for example:

using Microsoft.Web.Administration;
....
int iisNumber = 60000;
using (ServerManager serverManager = new ServerManager())
{
  var site = serverManager.Sites.Where(s => s.Id == iisNumber).SingleOrDefault();
  if (site != null)
  {
    site.Stop();
  }
}

这两个程序集都出现在 GAC 中并且是纯 MSIL(即使有一个 COM 互操作层可以直接与 IIS7 的底层管理机制对话)。

底层配置文件applicationHost.configadministration.config仅对 64 位编辑器(例如 notepad.exe 或 NotePad2.exe)可见,我怀疑这就是我的代码无法修改 administration.config 的原因通过 Microsoft.Web.Management

为什么 Microsoft.Web.Administration请允许我阅读/修改 applicationHost.config在 32 位进程中但是 Microsoft.Web.Management只能读取/修改 administration.config如果在 64 位进程中运行?

我无法将我的项目重新编译为目标 x64,因为它依赖于我们没有源代码的 32 位 COM 库。我可以构建一个解决方案,其中涉及调用进程外的 64 位 WCF 应用程序(或类似的东西),但我不想这样做。

最佳答案

经过一些挖掘,这看起来像是一个错误:

这个论坛帖子和 Carlos Aguilar 的帖子解释了所有内容:

http://forums.iis.net/p/1157779/1956471.aspx

Now I understand the issue, what is happening is that Cassini is a 32 bit process and that in conjunction of a bug in our configuration makes us try to load the "redirected" syswow (instead of system32) which is the reason why we cannot find administration.config. Running in 64 bit process alleviates the problem cause there is no "magic" redirection and we go to the right folder.

任何 32 位进程都会遇到这个路障。

关于windows - 为什么使用IIS7.5的Microsoft.Web.Management.dll只能在64位进程中使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3735540/

相关文章:

windows - 如何修复 Apache 服务器 (Windows) 中的导入 ssl 错误

c# - Server.ClearError()是否阻止IIS快速故障保护

Android SDK 管理器在 Windows 8 64 位上失败

windows - 为什么 git-upload-pack(在 git clone 期间)会挂起?

java - 读取文件添加到文件夹的时间

c# - 为什么异常中断应用程序池?

asp.net - 即使在服务器上也不会显示详细的500错误消息

java - 使用 Java 从 URL 下载 EXE 文件出现兼容性错误

c# - 如何将两个托管 x86/x64 dll 组合成一个托管 AnyCpu 库?

PHP内存缓存问题