有没有办法访问 web.config 文件中的 标记?
我想检查文件中 "debug" 属性是否设置为 "true",但是我似乎无法弄清楚如何做到这一点。我尝试使用
更新:
我知道我可以像加载 XML 文档一样加载文件并使用 XPath,但我希望框架中已经有一个可以为我完成此操作的东西。因为已经有方法可以获取应用程序设置和连接字符串,所以似乎应该有类似的东西。
我还尝试过几种方式使用
我想检查文件中 "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>
- cameron