繁体   English   中英

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

[英]Why is the ConfigurationManager.GetSection “system.webServer/handlers” not available?

我正在尝试在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}处理程序: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>

笔记:

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

至今: 在此处输入图片说明 看起来像system.webServer被忽略了。

根据您的OS /设置,可以将system.webServer元素配置为忽略-因此配置系统将不会从中构造任何内部配置项。 例如,在我的计算机(WinXP,IIS 5.1)上,默认情况下将其设置为忽略。

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

尝试:

** ps我的web.config包含: <httpHandlers>而不是您的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这就是本节的问题-他没有可以使用的唯一元素名称。 这就是为什么将其全部(“添加”元素)并解析它的原因。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM