简体   繁体   English

在运行时更改web / app.config

[英]Changing web/app.config at runtime

When I change a field in an web or app.config of a C# project, would that value automatically feed into the program without any restarts or interruptions in the program? 当我更改C#项目的web或app.config中的字段时,该值会自动输入到程序中而不会在程序中重新启动或中断吗? Is the program always fetching from the config files every time that field is requested or is it cached by the program somewhere. 程序是否总是在每次请求该字段时从配置文件中获取文件,还是由程序将其缓存在某处。 How does this work? 这是如何运作的?

I want a situation where I would change the value in the config, and want that value automatically pulled by the application like instantly. 我想要一种情况,我可以更改配置中的值,并希望该值由应用程序像瞬间那样自动提取。 Changes, and program pulls that value instantly. 进行更改,然后程序立即将其取值。

ASP.NET monitors web.config file and will recycle AppDomain when it notice changes. ASP.NET监视web.config文件,并在注意到更改时将回收AppDomain。 It will wait for the current requests to be processed and will queue any new requests coming. 它将等待当前请求被处理,并将所有新请求排队。

So yes, the changes will be pulled be the application, but not instantly and not without interruption (although that depends on your definition of 'instantly'). 因此,是的,更改将被应用程序应用,但不是立即且并非不间断地进行(尽管这取决于您对“即时”的定义)。

You are supposed to change the web.config through code, as it results in restart of AppDomain. 您应该通过代码更改web.config,因为它会导致AppDomain重启。 You should make a new xml file for setting and change it through code. 您应该制作一个新的xml文件进行设置,并通过代码对其进行更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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