In this tutorials, I am going to explain how to read appSettings and connectionStrings values from the web.config file.
To do so, lets add one appSettings and connectionStrings into our web.config file like this
<appSettings>
<add key="AppKey" value="Value in AppSetting key"/>
</appSettings>
<connectionStrings>
<add name="ConnStr" connectionString="server=localhost;database=mydatabase;uid=uid;pwd=pwd;"/>
</connectionStrings>
In the code behind file, you will have to use System.Configuration namespace. So add it at the top of the .cs file like
using System.Configuration;
Now, write the following code to retrieve the values from the web.config appSettings and connectionStrings.
string str = "connectionStrings value: " + ConfigurationManager.ConnectionStrings["ConnStr"].ToString();
str += "<br />appSetting value: " + ConfigurationManager.AppSettings["AppKey"].ToString();
litText.Text = str;
Is that simple???
Write any feedback or question you have.