写入后重新加载app.config
当我使用它写入我的 app.config 文件时:
Configuration config =ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["Wachtwoord"].Value = "Test";
config.Save();
ConfigurationManager.RefreshSection("appSettings");
我可以再次读取它。但是当我关闭并重新启动程序时,“Wachtwoord”的值再次更改为旧值。
有人知道我该如何解决这个问题吗?
谢谢
When I use this to write to my app.config file:
Configuration config =ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["Wachtwoord"].Value = "Test";
config.Save();
ConfigurationManager.RefreshSection("appSettings");
I can read it again. But when i close and restart the program, the value of "Wachtwoord" has changed again to the old value.
Does anybody how I could fix this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确定这不是由 Visual Studio 在构建项目时覆盖您的设置文件引起的吗?原始设置文件与源代码一起存在,而您从构建输出目录(例如 bin\debug)运行应用程序。运行应用程序时,您可能会更改构建输出目录中的副本,这将更改那里的版本。当您重建项目时,设置文件将被覆盖。
Are you sure that this has not been caused by Visual Studio overwriting your settings file when you build the project? The original settings file lives with your source code, whereas you run the application from your build output directory (e.g. bin\debug). You may be making changes to the copy in the build output directory when you run the application, which will make changes to the version there. When you rebuild the project, the settings file will be overwritten.