【发布时间】: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