为什么 ConfigurationManager.GetSection 是“system.webServer/handlers”?无法使用?

发布于 2024-12-24 03:00:41 字数 1071 浏览 2 评论 0原文

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

ConfigurationManager.GetSection("system.web/httpHandlers") {System.Web.Configuration.HttpHandlersSection} 基础{System.Configuration.ConfigurationSection}:{System.Web.Configuration.HttpHandlersSection} 处理程序:计数 = 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>

注意:

  • 嵌套。
  • ConfigurationManager.GetSection 默认情况下考虑

Web.configs 是嵌套的 远的: 在此处输入图像描述 看起来 system.webServer 被忽略了。

I'm trying to read some configuration in my global.aspx Application_Start method. When I read ConfigurationManager.GetSection("system.web/httpHandlers") everything is fine:

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

But when I read ConfigurationManager.GetSection("system.webServer/handlers") (which contains my custom handlers, it returns null. What am I doing wrong?

The section looks like this:

<system.webServer>
    <handlers>
        <add verb="*" path="*.loc" name="LocalizedResourceStreamer" 
                 type="CFW.WebUI.HttpHandlers.LocalizedResourceStreamer,WebUI" />
    </handlers>
</system.webServer>

Notes:

  • Web.configs are nested, ConfigurationManager.GetSection takes nesting into account by default.
  • The overall problem is trying to see if *.loc files are being served.

So far:
enter image description here
Looks like the system.webServer is ignored.

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

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

发布评论

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

评论(2

岛歌少女 2024-12-31 03:00:41

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

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

Depending on your OS/setup, the system.webServer element may be configured to be ignored - and so the config system will not be constructing any inner configuration items from it. E.g. on my machine (WinXP, IIS 5.1), it's set to ignored by default.

Check the machine.config on the machine where this code is running, and see how the system.webServer element is configured. I don't have machines available with suitable later OSes at the moment, but it may be that this element is always set to be ignored - after all, that part of the config is for IIS' use, rather than our own.

少女七分熟 2024-12-31 03:00:41

尝试:

**ps 我的 web.config 包含: 而不是您的 handlers 。必要时进行更改:) - 还有网络服务器与 system.web **

在此处输入图像描述

   Configuration webConfig = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);

        ConfigurationSection webConfigSections = webConfig.GetSection("system.web/httpHandlers");
        if (webConfigSections != null)
        {
         //   PropertyInformationCollection t = webConfigSections.ElementInformation.Properties;

            XDocument xmlFile = XDocument.Load(new StringReader(webConfigSections.SectionInformation.GetRawXml()));
            IEnumerable<XElement> query = from c in xmlFile.Descendants("add") select c;

            foreach (XElement band in query)
            {
            }


        }

ps 这就是本节的问题- 他没有可以使用的唯一元素名称。这就是为什么你把它整个(“添加”元素)并解析它。

try :

**p.s. my web.config contains : <httpHandlers> and not handlers as yours. change as necessarily :) - also the webserver vs system.web **

enter image description here

   Configuration webConfig = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);

        ConfigurationSection webConfigSections = webConfig.GetSection("system.web/httpHandlers");
        if (webConfigSections != null)
        {
         //   PropertyInformationCollection t = webConfigSections.ElementInformation.Properties;

            XDocument xmlFile = XDocument.Load(new StringReader(webConfigSections.SectionInformation.GetRawXml()));
            IEnumerable<XElement> query = from c in xmlFile.Descendants("add") select c;

            foreach (XElement band in query)
            {
            }


        }

p.s. thats the problem with this section - he doesnt have a uniquee element name that can be taken. thats why you take it whole("add" element) and parse it.

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