How to programmaticaly change the web.config?
How to programmaticaly change the web.config?
am 22.12.2007 05:18:54 von PSiegmann
Hello group..
Is there a way to change web.config entries at runtime? I haven't
found a class for that.
I have around 20 entries in the web.config, and I want a add a
configuration menu into my app, so that the administrator can change
some of the settings, without editing the web.config directly with a
text editor.
Re: How to programmaticaly change the web.config?
am 22.12.2007 09:57:57 von Riki
PSiegmann@mail.nu wrote:
> Hello group..
>
> Is there a way to change web.config entries at runtime? I haven't
> found a class for that.
> I have around 20 entries in the web.config, and I want a add a
> configuration menu into my app, so that the administrator can change
> some of the settings, without editing the web.config directly with a
> text editor.
In ASP.NET 2.0, you can use the System.Configuration classes, see
http://www.codeproject.com/KB/dotnet/mysteriesofconfiguratio n.aspx
You can also write to the web.config file in the same way as you would to
any XML file, something like (in VB.NET):
-----------------------------
Try
' Open web.config file
Dim doc As New XmlDocument()
doc.Load(Server.MapPath("web.config"))
Dim strSel As String
' Use an XPath query to look up the user element in this configuration
having
' a matching "name" attribute
strSel =
"/configuration/system.web/authentication/forms/credentials/ user[@name='" &
strUserName & "']"
Dim node As XmlNode = doc.SelectSingleNode(strSel)
' Modify the element
Dim element As XmlElement = CType(node,XmlElement)
element.SetAttribute("password",strHash)
' Save the configuration
doc.Save(Server.MapPath("web.config"))
Catch ex As Exception
Trace.Warn(ex.ToString())
End Try
------------------------------
Keep in mind that changing web.config may cause your application to restart,
thereby losing the session information for all users.
--
Riki
Re: How to programmaticaly change the web.config?
am 22.12.2007 10:02:05 von Mark Stevens
Is this any use http://odetocode.com/Articles/418.aspx
Regards,
Mark
On Fri, 21 Dec 2007 20:18:54 -0800 (PST), PSiegmann@mail.nu wrote:
>Hello group..
>
>Is there a way to change web.config entries at runtime? I haven't
>found a class for that.
>I have around 20 entries in the web.config, and I want a add a
>configuration menu into my app, so that the administrator can change
>some of the settings, without editing the web.config directly with a
>text editor.
--
|\ _,,,---,,_ A picture used to be worth a
ZZZzzz /,`.-'`' -. ;-;;, thousand words - then along
|,4- ) )-,_. ,\ ( `'-' came television!
'---''(_/--' `-'\_)
Mark Stevens (mark at thepcsite fullstop co fullstop uk)
Re: How to programmaticaly change the web.config?
am 23.12.2007 11:35:57 von Eliyahu Goldin
The way to go is to put all your setting that can change in a separate file.
Put this line in the section on web.config
Having done that, you can access parameteres in MySettings.xml via
ConfigurationManager.AppSettings.
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
wrote in message
news:dfecc965-bdd3-46bb-91bc-07cef6e2988b@i3g2000hsf.googleg roups.com...
> Hello group..
>
> Is there a way to change web.config entries at runtime? I haven't
> found a class for that.
> I have around 20 entries in the web.config, and I want a add a
> configuration menu into my app, so that the administrator can change
> some of the settings, without editing the web.config directly with a
> text editor.