Application parameters in the database
I want to centrally find all the settings of my application in the database. I have a database object that stores app.settings settings in an XML column. I would like my application to read this object and then parse the XML column in its own application settings. Is there an easy way to randomly read an XML object in your current settings?
source to share
Read the object from the XML object and then through your code you can save your config file as:
Configuration configFile = WebConfigurationManager.OpenWebConfiguration ("~");
AppSettingsSection AppSection = configFile.GetSection ("AppSettings") as AppSettingsSection;
AppSection.Settings.Add (new KeyValueConfigurationElement ("SMTP", "Mail.bhaidar.net"));
configFile.Save ();
The above code will add the following line to the appSettings section.
<appSettings>
< add key="SMTP" value="mail.bhaidar.net" / >
</appSettings>
source to share
It might be possible, but in case it isn't, I like to do the following:
- Never call ConfigurationaManager directly - wrap the whole thing in your own settings class and call it.
- Then you can place your settings wherever you want and change strategies flexibly. You can do each row setting in the database table, use the normal web.config application settings, or switch some other method along the way.
source to share