Reading a key from the Web Config using ConfigurationManager

0 votes

I need to read keys from web.config file. Here's what I write

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

And this is the appSettings in the Web.config:

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

When I debug the code, the username and password are both null, indicating that the keys are not being read.

What am I doing wrong when it comes to reading these numbers?

Jun 10, 2022 in C# by rajiv
• 1,620 points
881 views

1 answer to this question.

0 votes

Instead of any other thing, use the WebConfigurationManager class. Consider the following scenario:

string userName = WebConfigurationManager.AppSettings["PFUserName"]
answered Jun 11, 2022 by pranav
• 2,580 points

Related Questions In C#

0 votes
1 answer

Rich Text Editor on a web page

Perhaps something along the lines of TinyMCE ...READ MORE

answered May 30, 2022 in C# by rajiv
• 1,620 points
74 views
0 votes
1 answer

How to find the extension of a file in C#

Go to here https://docs.microsoft.com/en-us/dotnet/api/system.io.path.getextension?redirectedfrom=MSDN&view=net-6.0#System_IO_Path_GetExtension_System_String_ string myFilePath = @"C:\MyFile.txt"; string ext ...READ MORE

answered Jun 21, 2022 in C# by jyoti
• 1,240 points
122 views
0 votes
1 answer

What is the difference between a field and a property

The internal workings of a class should ...READ MORE

answered Jun 21, 2022 in C# by jyoti
• 1,240 points
94 views
0 votes
0 answers

Learning C from a background in C#

I'd like to increase my programming expertise, ...READ MORE

Jun 11, 2022 in C# by jyoti
• 1,240 points
54 views
0 votes
1 answer

Embedding Power Bi Report Promise is not defined powerbi.js

IE does not yet support Promise. You ...READ MORE

answered Oct 30, 2018 in Power BI by Shubham
• 13,490 points
1,332 views
0 votes
0 answers

The page cannot be displayed because an internal server error has occurred on server

When  I've deployed the website I installed  ...READ MORE

May 23, 2022 in Others by Kichu
• 19,040 points
419 views
0 votes
1 answer

Examples of dynamic polymorphism in c#

Check the example of polymorphism below. We ...READ MORE

answered Jun 7, 2022 in C# by pranav
• 2,580 points
208 views
0 votes
1 answer

Logging DML operations in ASP.NET MVC project

There are several options. You might register an ...READ MORE

answered Jun 14, 2022 in C# by jyoti
• 1,240 points
262 views
0 votes
1 answer

Encapsulation of subclasses from a constructor in C#

If you think about it in terms ...READ MORE

answered Jun 11, 2022 in C# by pranav
• 2,580 points
78 views
0 votes
1 answer

How do I specify the exit code of a console application in .NET

Simply put, you can return the exit ...READ MORE

answered Jun 11, 2022 in C# by pranav
• 2,580 points
770 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP