为什么 ConfigurationManager.GetSection 是“system.webServer/handlers”?无法使用?
我正在尝试读取 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:
Looks like the system.webServer is ignored.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据您的操作系统/设置,
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 thesystem.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.尝试:
**ps 我的 web.config 包含:
而不是您的handlers
。必要时进行更改:) - 还有网络服务器与 system.web **ps 这就是本节的问题- 他没有可以使用的唯一元素名称。这就是为什么你把它整个(“添加”元素)并解析它。
try :
**p.s. my web.config contains :
<httpHandlers>
and nothandlers
as yours. change as necessarily :) - also the webserver vs system.web **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.