Manipulating Configuration Parameters: For example Variables in web.config #.Net Web Applications

Brought from (our old site): http://salearningschool.com/displayArticle.php?table=Articles&articleID=1324&title=Manipulating%20Configuration%20Parameters:%20For%20example%20Variables%20in%20web.config

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:


//Compiled
Configuration myConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");

//change values for the variables in the AppSettings section
myConfig.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 value
string statusr = WebConfigurationManager.AppSettings["userLoginStatus"].ToString();

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

From: http://sitestree.com/?p=3726
Categories:.Net Web Applications
Tags:
Post Data:2016-07-16 11:06:25

    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>

Leave a Reply