Manipulating Configuration Parameters: For example Variables in web.config #19

To access a variable value, you can use the following type of code

string statusr = WebConfigurationManager.AppSettings["userLoginStatus"].ToString();
You will need to use: using System.Web.Configuration;or you can write as follows:string statusr = System.Web.Configuration.WebConfigurationManager.AppSettings["userLoginStatus"].ToString();

What about if you want to change the values of the variables in the web.config file. Check the code below:

//CompiledConfiguration myConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");//change values for the variables in the AppSettings sectionmyConfig.AppSettings.Settings["userLoginStatus"].Value = "1";//change values for the connection strings section        myConfig.ConnectionStrings.ConnectionStrings["myDatabaseName"].ConnectionString = "Data Source=....";myConfig.Save();//will return you the new valuestring statusr = WebConfigurationManager.AppSettings["userLoginStatus"].ToString();

The above code used:
System.Web.Configuration;
using System.Configuration;

A sample web.config file

From: http://sitestree.com/?p=5303
Categories:19
Tags:
Post Data:2007-10-10 15:52:36

    Shop Online: <a href='https://www.ShopForSoul.com/' target='new' rel="noopener">https://www.ShopForSoul.com/</a>
    (Big Data, Cloud, Security, Machine Learning): Courses: <a href='http://Training.SitesTree.com' target='new' rel="noopener"> http://Training.SitesTree.com</a> 
    In Bengali: <a href='http://Bangla.SaLearningSchool.com' target='new' rel="noopener">http://Bangla.SaLearningSchool.com</a>
    <a href='http://SitesTree.com' target='new' rel="noopener">http://SitesTree.com</a>
    8112223 Canada Inc./JustEtc: <a href='http://JustEtc.net' target='new' rel="noopener">http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning) </a>
    Shop Online: <a href='https://www.ShopForSoul.com'> https://www.ShopForSoul.com/</a>
    Medium: <a href='https://medium.com/@SayedAhmedCanada' target='new' rel="noopener"> https://medium.com/@SayedAhmedCanada </a>