How to read a key from the Web.Config file in ASP.NET app using C# ?


This content was proof-read by Grammarly. You can Try Grammary for FREE

If you want to read the values based on the key from the web.config file in your ASP.NET application using C# , you can use the  WebConfigurationManager to do it.

How to read a key from the Web.Config file in ASP.NET app using C# ?

Assume that the configuration file contains the below values

<configuration>
   <appSettings>
      <add key="UserName" value="username"/>
   </appSettings>
</configuration>

If you want to read the value of the key (“UserName”) , you can use the WebConfigurationManager as shown below.

string userNameValue = WebConfigurationManager.AppSettings["UserName"]
Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

%d bloggers like this: