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
5,018 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,590 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
678 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
644 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
641 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
319 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
2,064 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
1,112 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,590 points
862 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
1,198 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,590 points
714 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,590 points
2,462 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