阅读使用ConfigurationManager中Web.Config中的关键 [英] Reading a key from the Web.Config using ConfigurationManager

查看:155
本文介绍了阅读使用ConfigurationManager中Web.Config中的关键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图读取Web.config文件中的键不同的层网络层(同解)

I am trying to read the keys from the web.config file in a different Layer than the web layer (Same Solution)

下面是我试图

string userName = System.Configuration.ConfigurationManager.AppSettings["PFUserName"];
string password = System.Configuration.ConfigurationManager.AppSettings["PFPassWord"];

这是我的我的AppSettings在web.config文件

And here is my my appsettings in the web.config file

<configuration>
   ....
   <appSettings>
      <add key="PFUserName" value="myusername"/>
      <add key="PFPassWord" value="mypassword"/>
   </appSettings>
   ....
</configuration>

当我调试code用户名和密码都只是空,所以它没有得到键的值。
我在做什么错读这些价值?
谢谢!

when I debug the code username and password are just null, so it is not getting the value of the keys. What am I doing wrong to read these values? Thanks!

推荐答案

尝试使用WebConfigurationManager类代替。例如:

Try using the WebConfigurationManager class instead. For example:

string userName = WebConfigurationManager.AppSettings["PFUserName"]

这篇关于阅读使用ConfigurationManager中Web.Config中的关键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆