【发布时间】:2010-09-28 21:57:48
【问题描述】:
有什么方法可以访问 web.config 文件中的<compilation /> 标签?
我想检查文件中的“debug”属性是否设置为“true”,但我似乎不知道该怎么做.我尝试过使用WebConfigurationManager,但这似乎无法让我进入<compilation /> 部分。
更新:
我知道我可以像 XML 文档一样轻松地加载文件并使用 XPath,但我希望框架中已经有一些东西可以为我做这件事。似乎会有一些东西,因为已经有获取应用程序设置和连接字符串的方法。
我也尝试过以几种方式使用WebConfigurationManager.GetSection() 方法:
WebConfigurationManager.GetSection("compilation")// Name of the tag in the file
WebConfigurationManager.GetSection("CompilationSection") // Name of the class that I'd expect would be returned by this method
WebConfigurationManager.GetSection("system.web") // Parent tag of the 'compilation' tag
以上所有方法都返回null。我假设有一种方法可以访问此配置部分,因为已经存在一个类('CompilationSection'),我只是不知道如何获取它。
【问题讨论】:
-
您是否将您的部分添加到
configSections?类似:<configSections> <section name="compilation" type="xxx" /> ... </configSections>
标签: c# .net asp.net configuration