运行时 appconfig 值更改

发布于 2024-11-19 14:18:43 字数 137 浏览 6 评论 0原文

我想询问有关读取应用程序配置属性值的问题。

我可以在运行时更改一些应用程序配置属性值,并且可以在代码中使用该属性值。那么,如何在我的代码中获取运行时更改的应用程序配置属性值?在 C#.NET 中是否有任何选项可以获取运行时更改的应用程序配置值?

I want to ask about reading the app config property value.

I can change some of the app config property value during runtime and I could use that property value in my code. So, how to get that runtime changed app config property value in my code? Is there any options to get the runtime changed app config value in C#.NET?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

意中人 2024-11-26 14:18:43

保存对应用程序配置的更改后,执行以下操作

ConfigurationManager.RefreshSection(sectionName);

以获取更新的值。

请查看此页面

After saving the changes to the app config, do like this

ConfigurationManager.RefreshSection(sectionName);

to get the updated values.

Have a look at this page.

那片花海 2024-11-26 14:18:43

您可以使用 ConfigurationManager 修改配置文件,然后在保存设置后使用 RefreshSection 但如果您使用 ,您如何尝试访问新信息GetSection 那么当它从缓存中读取时,您不太可能获得更改。我认为您必须使用 OpenExeConfiguration 来阅读新的更改。

在运行时更改配置不是一个好习惯,您应该选择再次重新审视您的目的

You can use ConfigurationManager to modify the config files and then use the RefreshSection after saving the settings but how are you trying to access the new information in case you are using GetSection then its unlikely you would get the changes as its getting read from cache. You will have to use OpenExeConfiguration i think to read the new changes.

It is not a good practice to change the configurations at runtime you should choose to revisit your purpose once again

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文