I am trying to read the keys from the Web.config
file in a different layer than the web layer (Same solution)
Here is what I am trying:
string userName = System.Configuration.ConfigurationManager.AppSettings["PFUserName"]; string password = System.Configuration.ConfigurationManager.AppSettings["PFPassWord"];
And here is my appSettings
in the Web.config
file:
<configuration> .... <appSettings> <add key="PFUserName" value="myusername"/> <add key="PFPassWord" value="mypassword"/> </appSettings> .... </configuration>
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?
The ConfigurationManager class enables you to access machine, application, and user configuration information. This class replaces the ConfigurationSettings class, which is deprecated. For web applications, use the WebConfigurationManager class.
it is a .net builtin mechanism to define some settings before the application starts, without recompiling. see msdn configurationmanager.
Try using the WebConfigurationManager class instead. For example:
string userName = WebConfigurationManager.AppSettings["PFUserName"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With