Monday, March 18, 2013

How to read value from Web.Config file in ASP.NET

We can use Web.Config file to store any string value and that can be used in our ASP.NET application. After deploying the application also we can change the value in the config file. To do so,

In Web.Config file add a key and value that can be used in your application within the appSettings tags like below.
    <configuration>  
        <appSettings>  
            <add key="KEYNAME" value="KEYVALUE"/>  
        </appSettings>  
    </configuration> 
To retrieve the value use the below code,
string value = System.Configuration.ConfigurationManager.AppSettings["KEYNAME"].ToString();

No comments:

Post a Comment