我不想为我的应用程序创建单独的配置文件,而是将数据存储在 web.config 中。
我只想将一些 XML 放在那里并手动解析它,因为 ConfigurationManager 的当前实现不适合我的情况。
但是,如果没有虚拟类和属性,我就无法在其中添加 XML 而不会出现配置错误:解析器错误消息:无法识别的元素 XXXXX。即使我创建了虚拟配置类,我也无法在所有情况下修复此错误...
有什么方法可以标记我的 XML 不被解析,以便我可以使用 System.XML 手动获取数据。
谢谢。
最佳答案
使用 System.Configuration.IgnoreSectionHandler。
例子:
<configuration>
<configSections>
<section
name="myCustomSection"
type="System.Configuration.IgnoreSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowLocation="false" />
</configSections>
...
<myCustomSection>
...
</myCustomSection>
...
</configuration>
关于configuration - 有什么方法可以将部分添加到不会被 ConfigurationManager 解析的 .config 文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/888445/