【发布时间】:2016-01-05 15:38:34
【问题描述】:
我正在尝试使用以下代码获取配置文件:
public void EncryptConnString()
{
Configuration config = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Server.MapPath(@"/"));
ConfigurationSection section = config.GetSection("connectionStrings");
if (!section.SectionInformation.IsProtected)
{
config.Save(ConfigurationSaveMode.Modified);
}
}
但我得到了错误
此处不允许使用相对虚拟路径“F:/xxxx/yyyy/sample/”。
注意:我在global.asax 页面访问此代码我做错了什么?
【问题讨论】:
-
HttpContext.Current.Server.MapPath("~/")
-
对不起,遇到同样的错误!
-
注意:我在 global.asax 中访问此代码,如果我在页面方法中调用相同的方法意味着它的工作正常
-
更新了页面方法
标签: c# asp.net configuration web-config global-asax