【发布时间】:2011-07-05 06:48:04
【问题描述】:
我想通过 Web 应用程序的前端向用户公开一些 web.config 设置。我可以毫无问题地检索设置,但是当我保存时,我要么收到错误,要么更改没有保存到 web.config 文件中。我正在VS中调试。
如果我运行这个:
private void SaveWebConfig()
{
Configuration webConfig = WebConfigurationManager.OpenWebConfiguration("~//Web.config");
webConfig.AppSettings.Settings["DocumentPath"].Value = this.txtDocumentsDirectory.Text;
webConfig.Save();
}
我收到以下错误: 无法为请求的配置对象创建配置文件。
如果我运行这段代码,什么都不会发生:
private void SaveWebConfig()
{
Configuration webConfig = WebConfigurationManager.OpenWebConfiguration("~//Web.config");
webConfig.AppSettings.Settings["DocumentPath"].Value = this.txtDocumentsDirectory.Text;
webConfig.SaveAs("~//Web.config");
}
【问题讨论】:
标签: c# asp.net web-config