【发布时间】:2016-08-04 14:21:18
【问题描述】:
我正在使用 Asp.net 动态网站应用程序,无法将配置保存到 web.config 文件中。
我尝试过类似的方法,但不起作用!
var configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
configuration.AppSettings.Settings["Value"].Value = "Some value";
configuration.Save();
我遇到的错误
1. OpenWebConfiguration(Server.MapPath(".")) & OpenWebConfiguration(Server.MapPath("~"):
The relative virtual path 'C:/...' is not allowed here.
2. OpenWebConfiguration("~")
An error occurred loading a configuration file: Failed to map the path '/'.
我真的不知道该怎么办了。
【问题讨论】:
-
您不想在运行时修改您的 Web 配置。您将强制您的应用程序池/Web 应用程序重新启动执行此操作,结果您将丢失所有会话并在下一次请求时产生开销。相反,您希望将此数据持久保存到数据库中的表中。
标签: asp.net web-config save