web.config

  • Thread starter Thread starter mocsoft
  • Start date Start date
M

mocsoft

I have an application that requires the dynamic changing of values in
the web.config file, I have code that seems to change the value:

WebConfigurationManager.AppSettings("database") =
DropDownList1.SelectedValue

However this seems to hold the value in IIS memory rather than actually
changing the stored text in the web.config file.

Does anyone know how I could change the value in the file permenantly
and programmatically?

Any help much appreciated
 
If you are using 2.0, create additional XML files and link them to the
config. Then, you can edit to your hearts content. Note, however, that any
items pulled at start up will have to be changed in memory, as well.

Nice starter article:
http://www.aspnetpro.com/newsletterarticle/2006/06/asp200606tf_l/asp200606tf_l.asp

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
Think outside of the box!
*************************************************
 
Got it sorted theres a great piece in ASP.Net 2 unleashed about editing
the web.config, here is the code i have used for my specific section,
if anyone needs any help with their own requirements dont hesitate to
ask.

selectedDB = DropDownList1.SelectedValue
Dim config As Configuration =
WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath)
Dim section As AppSettingsSection =
CType(config.GetSection("appSettings"), AppSettingsSection)
section.Settings.Item("database").Value = selectedDB
config.Save(ConfigurationSaveMode.Modified)

Ps: you must import Namespace="System.web.configuration"
 
Back
Top