|
 |
aspx thread: Modifying Web.Config through code???
Message #1 by "George Walley" <booyah@m...> on Fri, 14 Jun 2002 14:59:22
|
|
Does anyone know how/if you can modify a value in the Web.Config through
code while it's live on the server (assuming you can give your script
permission to read/write the Web.Config file)?
I have a value stored the pseudo-XML structure of the Web.Config file
which represents which database server to use, but this value should
change every day or every other day on a non-fixed schedule so I can't
depend on it being "Red" on Monday and "Blue" on Tuesday. Thus i need to
read the current and right another value (without changing the rest of
Web.Config - which code may change often as well)
Thanks,
george
Message #2 by Feduke Cntr Charles R <FedukeCR@m...> on Fri, 14 Jun 2002 10:15:00 -0400
|
|
George,
Someone else on one of these lists was asking a similiar question
for changing authentication methods and they haven't found a solution yet
either. However, your problem doesn't require a constant change does it?
If the occurance should only happen once a night, then my solution would be
to write an NT/2000 service (easy with .NET) and have it shut down the IIS
process and all related processes (as easy as fireing a batch file to "net
stop" the four associated services until you know the equivalent in .NET).
Then your service would open the Web.Config file with an XmlTextReader, make
the changes, and save the file. Finally restart the IIS process(es) again.
HTH,
- Chuck
-----Original Message-----
From: George Walley [mailto:booyah@m...]
Sent: Friday, June 14, 2002 10:59 AM
To: ASP+
Subject: [aspx] Modifying Web.Config through code???
Does anyone know how/if you can modify a value in the Web.Config through
code while it's live on the server (assuming you can give your script
permission to read/write the Web.Config file)?
I have a value stored the pseudo-XML structure of the Web.Config file
which represents which database server to use, but this value should
change every day or every other day on a non-fixed schedule so I can't
depend on it being "Red" on Monday and "Blue" on Tuesday. Thus i need to
read the current and right another value (without changing the rest of
Web.Config - which code may change often as well)
Thanks,
george
Message #3 by "Chris Kersey" <ckersey@m...> on Fri, 14 Jun 2002 08:00:48 -0700
|
|
Is it a feasible solution to point at the datasource using a DSN and then
change the DSN on the webserver programmatically using a scheduler or
service instead of altering the web.config?
just curious.
chris
----- Original Message -----
From: "Feduke Cntr Charles R" <FedukeCR@m...>
To: "ASP+" <aspx@p...>
Sent: Friday, June 14, 2002 7:15 AM
Subject: [aspx] RE: Modifying Web.Config through code???
> George,
>
> Someone else on one of these lists was asking a similiar question
> for changing authentication methods and they haven't found a solution yet
> either. However, your problem doesn't require a constant change does it?
> If the occurance should only happen once a night, then my solution would
be
> to write an NT/2000 service (easy with .NET) and have it shut down the IIS
> process and all related processes (as easy as fireing a batch file to "net
> stop" the four associated services until you know the equivalent in .NET).
> Then your service would open the Web.Config file with an XmlTextReader,
make
> the changes, and save the file. Finally restart the IIS process(es)
again.
>
> HTH,
> - Chuck
>
> -----Original Message-----
> From: George Walley [mailto:booyah@m...]
> Sent: Friday, June 14, 2002 10:59 AM
> To: ASP+
> Subject: [aspx] Modifying Web.Config through code???
>
>
> Does anyone know how/if you can modify a value in the Web.Config through
> code while it's live on the server (assuming you can give your script
> permission to read/write the Web.Config file)?
>
> I have a value stored the pseudo-XML structure of the Web.Config file
> which represents which database server to use, but this value should
> change every day or every other day on a non-fixed schedule so I can't
> depend on it being "Red" on Monday and "Blue" on Tuesday. Thus i need to
> read the current and right another value (without changing the rest of
> Web.Config - which code may change often as well)
>
> Thanks,
> george
>
>
Message #4 by "Garland Frye" <gfrye@s...> on Fri, 14 Jun 2002 13:39:18 -0500
|
|
if you try to write to the collection(Configuration.Settings.Item("node")
var) you will find that the public property in the configuration class is
readonly. The solution that I've seen is to open an xml stream, read in the
contents of web.config, then use an xml data document, change it, write it
back to disk with the name of web.config
Hope this helps,
Garland R. Frye
"George Walley" <booyah@m...> wrote in message
news:184458@a...
>
> Does anyone know how/if you can modify a value in the Web.Config through
> code while it's live on the server (assuming you can give your script
> permission to read/write the Web.Config file)?
>
> I have a value stored the pseudo-XML structure of the Web.Config file
> which represents which database server to use, but this value should
> change every day or every other day on a non-fixed schedule so I can't
> depend on it being "Red" on Monday and "Blue" on Tuesday. Thus i need to
> read the current and right another value (without changing the rest of
> Web.Config - which code may change often as well)
>
> Thanks,
> george
>
>
Message #5 by "Aaron Chavez" <achavez382@w...> on Fri, 21 Jun 2002 18:25:26
|
|
The documentation specifically addresses this issue...
(in ms-help://MS.VSCC/MS.MSDNVS/cpguide/html/cpconconfigurationfiles.htm)
"Managed code can use the System.Configuration API to read settings from
the configuration files, but not to write settings to those files."
Code running on the server treating the file as XML (rather than a config)
seems the best bet
achavez382
AT
worldsaving.com
> if you try to write to the collection(Configuration.Settings.Item
("node")
var) you will find that the public property in the configuration class is
readonly. The solution that I've seen is to open an xml stream, read in the
contents of web.config, then use an xml data document, change it, write it
back to disk with the name of web.config
Hope this helps,
Garland R. Frye
"George Walley" <booyah@m...> wrote in message
news:184458@a...
>
> Does anyone know how/if you can modify a value in the Web.Config through
> code while it's live on the server (assuming you can give your script
> permission to read/write the Web.Config file)?
>
> I have a value stored the pseudo-XML structure of the Web.Config file
> which represents which database server to use, but this value should
> change every day or every other day on a non-fixed schedule so I can't
> depend on it being "Red" on Monday and "Blue" on Tuesday. Thus i need to
> read the current and right another value (without changing the rest of
> Web.Config - which code may change often as well)
>
> Thanks,
> george
>
>
|
|
 |