开发者

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 chang开发者_如何学Pythone 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜