【问题标题】:how can I get the child nodes of the <location> section in web.config?如何获取 web.config 中 <location> 部分的子节点?
【发布时间】:2011-12-24 06:51:49
【问题描述】:

我知道 HttpHandler 的名称,我需要获取包含此处理程序的 location 部分。所以我需要在我的 web.config 中获取所有 location 部分,然后获取 HttpHandlers 部分并检查其名称是否与我需要的相同:

<location path="myhandler">
  <system.web>
    <httpHandlers>
      <add verb="GET" path="Handler" type="location_element.MyHandler,location_element"/>
    </httpHandlers>
  </system.web>
</location>

我找到了如何获取 location 部分:

Configuration config = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);
ConfigurationLocationCollection locations = config.Locations;
foreach (ConfigurationLocation location in locations)
{
    //code
}

location 只有 Path 属性,我无法获取此部分的子元素。我发现方法是使用IConfigurationSectionHandler,这里描述了如何创建custom configuration handler。但问题是 location 部分不是自定义部分,所以我不能像在 MSDN 示例中那样使用我自己的 sectionHandler。

【问题讨论】:

    标签: c# configuration web-config location


    【解决方案1】:

    【讨论】:

      猜你喜欢
      • 2010-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多