问题描述
我有来自某个应用程序的 web.config 文件.它位于某个随机位置.我必须解析这个 web.config 文件(获取所有键名和值).我尝试使用 ConfigurationManager 类来获取这些数据,但是,当我尝试获取某些部分 (Configuration->GetSection('section name')) 时,它会引发异常.它抛出异常,因为我没有本节指向的 dll(因为我只有 web.config 而不是整个应用程序).似乎 GetSection 方法检查底层 dll 以获取更多信息,但我只需要值(dll 的名称).
I have web.config file from some application. It is located in some random location. I have to parse this web.config file (get all keys names and values). I tried to use ConfigurationManager class in order to get those data however, it throws exception when I try to get some Sections (Configuration->GetSection('section name')). It throws exception because I do not have dll that this section points to (because I have only web.config not whole application). It seems that GetSection method check underlying dll in order to get more info, but I just need value (name of dll).
我该怎么办,关闭这个机制,你知道其他简单的解决方案吗?
What can I do, to turn off this mechanism, do you know other simple solutions to get it done ?
推荐答案
您只需要使用 XmlDocument 或 XDocument (3.5) 来解析文件.
You are just going to have to use XmlDocument or XDocument (3.5) to parse the file.
这篇关于如何在c#中解析web.config文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!