Edit Web.Config from within Site?

X

xeroxero

I have several web.config values that I would like to change via a web
page within my ASP.NET 2.0 Web Application Project. Is it possible to
do so, assuming the ASPNET user has filesystem permissions to write to
the file? I thought I could use an XmlTextReader to slurp the file in,
make accept textbox values, use the DOM to change the right values,
and write the file back. If it works, the app would thenautomatically
re-load with the new changes.

Does any of that make sense?


Thanks.
 
G

Guest

xeroxero,
You could do it, but the problem is that as soon as you modify the
web.config your ASP.NET application is going to restart, and you may end up
with a real mess on your hands.

Better to use a separate xml file or a database for such settings.
Peter
 
B

Brennan Stehling

An update to the web.config also causes the web application to restart.
Look at the web-based installers for products like Community Server
and DotnetNuke. Those projects also update the web.config, but have
experienced issues with doing it.

Brennan Stehling
http://brennan.offwhite.net/blog/
 
B

Brennan Stehling

xeroxero,

Here is some info you can use:

Search for restart on this page...
http://msdn2.microsoft.com/en-us/library/ms228154.aspx
http://msdn2.microsoft.com/en-us/li...tioninformation.restartonexternalchanges.aspx

What I would do is Peter is suggesting. You can place a configuration
file called custom.config and access it this way...

string configFile =
Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath,
"custom.config");

Since it ends with .config it will be protected just like Web.config
and any file ending with .config. I use log4net for logging and place
log4net.config into a separate file so that I can reconfigure logging
in a Production setting with restarting the web application.

Brennan Stehling
http://brennan.offwhite.net/blog/
 

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