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

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"]

Leave Your Comment