在 Vista 上,针对 IIS 的 ADSI 查询与 IIS 管理器不一致

发布于 2024-08-13 02:58:57 字数 796 浏览 8 评论 0原文

使用 Vista...

我有一个使用 ADSI 在 IIS 网站上设置 ScriptMap 的脚本。它是 javascript,在 cscript.exe 中运行,代码如下所示:

var web = GetObject("IIS://localhost/W3SVC/1");
var maps = web.ScriptMaps.toArray();
map[maps.length] = ".aaa,c:\\path\\to\\isapi\\extension.dll,1,GET,POST";
web.ScriptMaps = maps.asDictionary();
web.SetInfo();

当我运行脚本后查看 IIS 管理器时,我可以在处理程序映射列表中看到新条目。它有一个奇怪的名称“AboMapperCustom-43155”,据我所知,它来自 ADSI 的 IIS7 兼容层。

如果在 IIS 管理器中删除这些处理程序映射,然后运行另一个 ADSI 脚本来查询 ScriptMaps 属性,则脚本中检索到的 ScriptMap 仍会列出刚刚删除的条目。 ADSI 脚本中的结果与 IIS 管理器中显示的“处理程序映射”列表不一致。

即使在启动/停止 IISADMIN 和 W3SVC 后,这种情况仍然存在。

这是预期的行为吗? ADSI 在 IIS7 中作为“兼容模式”得到支持。这是那个的神器吗?

我相信,如果从 IIS MANager 中删除处理程序映射,那么它就真的消失了,即使它仍然从 ADSI 查询中返回。

谁能对此提供任何澄清吗?

Using Vista...

I have a script that uses ADSI to set ScriptMaps on an IIS Website. It's javascript, run within cscript.exe, and the code looks something like this:

var web = GetObject("IIS://localhost/W3SVC/1");
var maps = web.ScriptMaps.toArray();
map[maps.length] = ".aaa,c:\\path\\to\\isapi\\extension.dll,1,GET,POST";
web.ScriptMaps = maps.asDictionary();
web.SetInfo();

When I look in the IIS Manager after running the script, I can see the new entry in the list of Handler Mappings. It has a weird name "AboMapperCustom-43155", which I understand comes from the IIS7 compatibility layer for ADSI.

If, in IIS Manager, I then remove those Handler Mappings, then run another ADSI script to query the ScriptMaps property, the retrieved ScriptMaps in the script still lists the entry that was just removed. The results in the ADSI script don't agree with the list of "Handler Mappings" shown in the IIS Manager.

This persists even after a start/stop of IISADMIN and W3SVC.

Is this expected behavior? ADSI is supported as a "compatibility mode" in IIS7. Is this an artifact of that?

I believe that if the Handler Mapping is removed from IIS MAnager, then it is really gone, even though it still gets returned from an ADSI query.

Can anyone offer any clarification on this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

铃予 2024-08-20 02:58:57

使用 ADSI 兼容性位添加“脚本映射”(为了论证而使用默认网站)时,这会添加一个处理程序映射到该站点的 applicationHost.config 文件:

<location path="Default Web Site">
  <system.webServer>
    <handlers>
        <add name="AboMapperCustom-12345678" ... />
    </handlers>
  </system>
</location>

当您 删除 IIS7 管理器中的处理程序映射,而不是从 applicationHost.config 文件和上面显示的部分中删除映射,而是将 web.config 文件添加到根目录使用

<configuration>
  <system.webServer>
    <handlers>
        <remove name="AboMapperCustom-12345678" />
    </handlers>
  </system>
</configuration>

新的托管 Microsoft.Web.Administration .NET API 获取网站的配置时,您可以读取不同级别的配置,例如:

1:读取 applicationHost.config 或 APPHOST 级别的配置

ServerManager serverManager = new ServerManager();
var site = serverManager.Sites.Where(s => s.Id == 1).SingleOrDefault();
Configuration siteConfig = serverManager.GetApplicationHostConfiguration();
ConfigurationSection handlersSection = 
     siteConfig.GetSection("system.webServer/handlers", site.Name);
ConfigurationElementCollection handlersCollection = 
     handlersSection.GetCollection();

foreach (var item in handlersCollection)
{
    Console.WriteLine(item.Attributes["name"].Value);
}

在上面的示例中,即使您已删除映射,在迭代处理程序映射集合时仍会列出它。这是因为您要求在应用程序主机级别进行配置。网站根目录或以下位置存在的任何 web.config 文件都不会被读取,并且它们的处理程序 会被读取。 指令不会被包含在内。

2:您可以读取特定于站点(或站点中的子文件夹)的配置:

ServerManager serverManager = new ServerManager();
Configuration siteConfig = serverManager.GetWebConfiguration("Default Web Site");    
ConfigurationSection handlersSection = 
    siteConfig.GetSection("system.webServer/handlers");
ConfigurationElementCollection handlersCollection = 
    handlersSection.GetCollection();

foreach (var item in handlersCollection)
{
    Console.WriteLine(item.Attributes["name"].Value);
}

这还将读取站点 web.config 文件并返回一个处理程序映射列表,用于说明 web.config 中指定的 指令。

这就是当您查看和修改处理程序映射时 IIS7 管理器应用程序正在执行的操作。它通过在站点根文件夹(或子文件夹)中创建(如果需要)web.config 文件并添加必需的 来添加和删除处理程序以及此级别的

IIS6 兼容层似乎仅在 applicationHost.config APPHOST 级别(上面的选项 1)运行,这就是您看到这些差异的原因。

这是一个错误吗?我不确定这是因为最终 ADSI 从来没有意识到 web.config 。此外,MS 还必须添加一个新方法或标志,以允许您指定您真正想要在哪个级别进行这些“脚本映射”更改,这可能意味着破坏和测试 ADSI 组件,这反过来可能会引入错误。该行为是为了模拟修改旧的 IIS6 元数据库,而 applicationHost.config 实际上与元数据库类似,因此您可以认为,无论正确与否,它正在做正确的事情。

When you add a 'scriptmap' using the ADSI compatibility bits (using the Default Web Site for the sake of argument), this adds a handler mapping to the applicationHost.config file for the site at:

<location path="Default Web Site">
  <system.webServer>
    <handlers>
        <add name="AboMapperCustom-12345678" ... />
    </handlers>
  </system>
</location>

When you delete the handler mapping in the IIS7 manager, instead of removing the mapping from the applicationHost.config file and the section shown above, a web.config file is added to the root of the site with the following:

<configuration>
  <system.webServer>
    <handlers>
        <remove name="AboMapperCustom-12345678" />
    </handlers>
  </system>
</configuration>

When getting the configuration for a website using the new managed Microsoft.Web.Administration .NET API you can read the config at different levels, for example:

1: Read the configuration at the applicationHost.config or APPHOST level

ServerManager serverManager = new ServerManager();
var site = serverManager.Sites.Where(s => s.Id == 1).SingleOrDefault();
Configuration siteConfig = serverManager.GetApplicationHostConfiguration();
ConfigurationSection handlersSection = 
     siteConfig.GetSection("system.webServer/handlers", site.Name);
ConfigurationElementCollection handlersCollection = 
     handlersSection.GetCollection();

foreach (var item in handlersCollection)
{
    Console.WriteLine(item.Attributes["name"].Value);
}

In the example above, even though you've removed the mapping, it will still be listed when iterating the handler mapping collection. This because you've asked for the configuration at the application host level. Any web.config files that exist in the site root or below will not be read and their handler <add/> and <remove/> directives will not be included.

2: You can read the configuration that is specific to a site (or subfolder in a site):

ServerManager serverManager = new ServerManager();
Configuration siteConfig = serverManager.GetWebConfiguration("Default Web Site");    
ConfigurationSection handlersSection = 
    siteConfig.GetSection("system.webServer/handlers");
ConfigurationElementCollection handlersCollection = 
    handlersSection.GetCollection();

foreach (var item in handlersCollection)
{
    Console.WriteLine(item.Attributes["name"].Value);
}

This will also read the site web.config file and will return a handler mapping list that accounts for the <add/> and <remove/> directives specified in the web.config.

This is what the IIS7 Manager application is doing when you are viewing and modifying handler mappings. It is adding and removing handlers by creating (if necessary) a web.config file in the site root folder (or subfolders) and adding the requisite <add/> and <remove/> at this level.

The IIS6 compatibility layer appears to operate solely at the applicationHost.config APPHOST level (option 1 above) which is why you're seeing these differences.

Is it a bug? I'm not sure it is because ultimately ADSI was never web.config aware in the first place. Also MS would have to add a new method or flag to allow you to specify at which level you really want to make these 'scriptmap' changes and that may mean breaking and testing the ADSI components, which in turn may introduce bugs. The behaviour is there to simulate modifying the old IIS6 metabase, and applicationHost.config is in effect analagous to the metabase so you could argue, rightly or wrongly, it's doing the right thing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文