Reading and Writing from Web.config
Hi Everyone. What is the simplest way to read from my web.config and write back to it? I want to store my SQL datasource there and return it when I want to open a connection to my SQL db's.
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Kapil Deo MalhotraRank #2,120 · 672 reputationPosted Apr 14, 2009, 1:43 PM EDT
To read the AppSettings from the Web.Config file you can use the ConfigurationSettings or ConfigurationManager Class.
It works like the following
string connectionInfo = ConfigurationSettings.AppSettings["ConnectionInfo"];
ConnectionInfo is in the Web.config file under the AppSettings like
For Writting into Web.config
Dim config As System.Configuration.Configuration = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath)
'Modify Existeing Key in Web.config
config.AppSettings.Settings.Item("SiteName").Value = "Value Changed"config.Save(ConfigurationSaveMode.Modified)
Hope that will help.
Space Ghost45 reputationPosted Apr 14, 2009, 2:09 PM EDT