简体   繁体   中英

Manipulating web.config in memory

I have a web.config file open in a textbox and would like to manipulate it. For example, allowing the user to change the DBConn string or something. At the stage of trying to change this, the config text may, or may not exist as a physical file. Is it possible to use the WebConfigurationManager, or similar in memory; something like this:

string myWebConfig = LoadWebConfigHere();

var config = WebConfigurationManager.OpenWebConfiguration(myWebConfig);

OpenWebConfiguration only accepts a path. I don't really want to save it and reload it to get this functionality.

This isn't possible, the web.config is only loaded once per request and changes cannot be "set"; any alterations to the file will only take effect once, say, the page is refreshed / reloaded.

So, whether this is an existing file, or is being compiled by means of your own logic, the above is the only way to utilise it by way of loading it into context.

cannot answer you via comments:)

For desktop application you better to use external configuration file or app.config.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM