[英]Relative virtual path is not allowed when using server.MapPath()
I am Trying to get the configuration file using the following code: 我正在尝试使用以下代码获取配置文件:
public void EncryptConnString()
{
Configuration config = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Server.MapPath(@"/"));
ConfigurationSection section = config.GetSection("connectionStrings");
if (!section.SectionInformation.IsProtected)
{
config.Save(ConfigurationSaveMode.Modified);
}
}
But i am getting the error 但是我得到了错误
The relative virtual path 'F:/xxxx/yyyy/sample/' is not allowed here. 此处不允许相对虚拟路径“ F:/ xxxx / yyyy / sample /”。
Note: I am accessing this code in global.asax
page What i am doing wrong? 注意:我正在global.asax
页面中访问此代码我在做什么错?
如果将null传递给此方法,它将为您返回根配置文件:
var config = WebConfigurationManager.OpenWebConfiguration(null);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.