web.config

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
 
C

Cowboy \(Gregory A. Beamer\)

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!
*************************************************
 
M

mocsoft

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"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top