我试图从Web.config与web层不同的层中读取文件中的键(相同的解决方案)
这是我正在尝试的:
string userName = System.Configuration.ConfigurationManager.AppSettings["PFUserName"];
string password = System.Configuration.ConfigurationManager.AppSettings["PFPassWord"];
Run Code Online (Sandbox Code Playgroud)
这是我appSettings在Web.config文件中:
<configuration>
....
<appSettings>
<add key="PFUserName" value="myusername"/>
<add key="PFPassWord" value="mypassword"/>
</appSettings>
....
</configuration>
Run Code Online (Sandbox Code Playgroud)
当我调试的代码username和password只是null,所以它是没有得到键的值.
读这些值我做错了什么?
当我尝试使用时检索.config文件中的部分列表
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
Run Code Online (Sandbox Code Playgroud)
config.Sections集合包含一堆系统部分,但我没有在configSections标记中定义文件的部分.