Edit Web.Config from within Site?

  • Thread starter Thread starter xeroxero
  • Start date Start date
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.
 
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
 
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/
 
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/
 
Back
Top