相关疑难解决方法(0)

使用ConfigurationManager从Web.Config中读取密钥

我试图从Web.config与web层不同的层中读取文件中的键(相同的解决方案)

这是我正在尝试的:

string userName = System.Configuration.ConfigurationManager.AppSettings["PFUserName"];
string password = System.Configuration.ConfigurationManager.AppSettings["PFPassWord"];
Run Code Online (Sandbox Code Playgroud)

这是我appSettingsWeb.config文件中:

<configuration>
   ....
   <appSettings>
      <add key="PFUserName" value="myusername"/>
      <add key="PFPassWord" value="mypassword"/>
   </appSettings>
   ....
</configuration>
Run Code Online (Sandbox Code Playgroud)

当我调试的代码usernamepassword只是null,所以它是没有得到键的值.

读这些值我做错了什么?

c# asp.net-mvc

272
推荐指数
4
解决办法
43万
查看次数

如何使用C#检索.config文件中的自定义配置节列表?

当我尝试使用时检索.config文件中的部分列表

Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
Run Code Online (Sandbox Code Playgroud)

config.Sections集合包含一堆系统部分,但我没有在configSections标记中定义文件的部分.

c# configurationmanager configsection

7
推荐指数
1
解决办法
3110
查看次数