为什么ConfigurationManager.GetSection"system.webServer/handlers"不可用?

Kee*_*ker 8 c# asp.net iis web-config httphandler

我正在尝试在我的global.aspx Application_Start方法中读取一些配置.当我读到ConfigurationManager.GetSection("system.web/httpHandlers")一切都很好:

ConfigurationManager.GetSection("system.web/httpHandlers"){System.Web.Configuration.HttpHandlersSection} base {System.Configuration.ConfigurationSection}:{System.Web.Configuration.HttpHandlersSection}处理程序:Count = 48

但是当我读ConfigurationManager.GetSection("system.webServer/handlers")(包含我的自定义处理程序,它返回null.我做错了什么?

该部分如下所示:

<system.webServer>
    <handlers>
        <add verb="*" path="*.loc" name="LocalizedResourceStreamer" 
                 type="CFW.WebUI.HttpHandlers.LocalizedResourceStreamer,WebUI" />
    </handlers>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)

笔记:

  • Web.configs是嵌套的,ConfigurationManager.GetSection默认情况下将嵌套考虑在内.
  • 整体问题是试图查看是否正在提供*.loc文件.

至今: 在此输入图像描述 看起来像system.webServer被忽略了.

Dam*_*ver 4

根据您的操作系统/设置,该system.webServer元素可能会被配置为被忽略 - 因此配置系统不会从中构造任何内部配置项。例如,在我的机器(WinXP、IIS 5.1)上,它默认设置为忽略。

检查machine.config运行此代码的计算机,并查看该system.webServer元素是如何配置的。我目前没有配备合适的后续操作系统的机器,但可能该元素始终被设置为忽略 - 毕竟,配置的该部分是供 IIS 使用的,而不是我们自己的。