read and write to the web.config file

T

tom

hello all,

i have a web application that i want users to be able to
change the name of the server and database from a web page.

i have got this to work using this...



code:-

Public Sub SetValue(ByVal key As String, ByVal value
As Object)
Dim ds As New DataSet()
ds.ReadXml(System.Web.HttpRuntime.AppDomainAppPath
& "web.config")
Dim dr() As DataRow = ds.Tables("add").Select
(String.Concat("key='", key, "'"))
dr(0).Item("value") = value
ds.WriteXml
(System.Web.HttpRuntime.AppDomainAppPath & "web.config")
ds.Clear()
End Sub



called by this:


code:-

Dim aw As New AppSettinsWriter()
aw.SetValue("ConnectionPCSRead", "data source=" &
txtServer.Text & ";initial catalog=" & lblDatabase.Text
& ";persist security info=False;user
id=sa;password=;packet size=4096")



but i need to display the server and database apon load of
the web page, so the user can see what they are editing!

at the mo it's just empty text boxes.

I need to display the "data source" in the server box,
and to display the "initial catalog" in the database box.

please could you help,

thanks,

Tom.
 
T

Teemu Keiski

Hi,

it is not recommendable to let users write straight to the web.config file,
because it will also restart the ASP.NET application every time. That means
losing cache every time and so on.

However Jason Gaylord has written couple of articles about the subject so
perhaps you got take a peek on that:
http://aspalliance.com/jgaylord/column/aspnet/xml/editwebconfig1.aspx
http://aspalliance.com/jgaylord/column/aspnet/xml/editwebconfig2.aspx

--
Teemu Keiski
MCP,Designer/Developer
Mansoft tietotekniikka Oy
http://www.mansoft.fi

ASP.NET Forums Moderator, www.asp.net
AspAlliance Columnist, www.aspalliance.com

Email:
(e-mail address removed)
 

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

Top