簡體   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