Posts

Posts uit december, 2009 tonen

[C#] Web.config aanpassen in code

Soms is het nodig om in de web.config een sectie te wijzigen. Een manier om een waarde van een sectie (of xml node) te wijzigen is om web.config in te lezen en dan aanpassen met XML objectecn. Een andere manier, die hier wordt besproken, is door gebruik te maken van Configuration classes. Onderstaand volgt een voorbeeld hoe je een waarde kunt aanpassen in de appSettings sectie. private void UpdateConfig( string strKey, string strValue) { Configuration objConfig = WebConfigurationManager.OpenWebConfiguration("~"); AppSettingsSection objAppsettings = (AppSettingsSection)objConfig.GetSection("appSettings"); if (objAppsettings != null ) { objAppsettings.Settings[strKey].Value = strValue; objConfig.Save(); } } bron: http://www.codeguru.com/csharp/.net/net_asp/miscellaneous/article.php/c13663/