简体   繁体   English

使用server.MapPath()时不允许使用相对虚拟路径

[英]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.

相关问题 StreamReader Server.MapPath-给定的物理路径,预期的虚拟路径 - StreamReader Server.MapPath - Physical path given, virtual path expected Server.MapPath - 给定的物理路径,预期的虚拟路径 - Server.MapPath - Physical path given, virtual path expected server.mappath 将引用的文件路径解析为相对目录 - server.mappath resolve referenced file path to relative dir 使用Server.MapPath()时如何从虚拟路径中排除控制器名称? - How can I exclude controller name from the virtual path when I use Server.MapPath()? Server.MapPath()返回与DirectoryInfo一起使用时不存在的路径 - Server.MapPath() returning a path that does not exist when used with DirectoryInfo 如何使用Server.MapPath读取相对Web路径,并在文件名或C#中使用空格字符 - How to read a relative web path with Server.MapPath with space character in filename or path in C# c# - 给定物理路径,Server.MapPath 中需要虚拟路径 - c# - Physical path given, virtual path expected in Server.MapPath Server.MapPath(virtualPath)返回控制器的根目录,也不返回IIS中虚拟目录中提到的物理路径 - Server.MapPath(virtualPath) Returns root directory of controller, it is nor returns the physical path mentioned in the virtual directory in IIS Server.MapPath不会返回映射到Web-App子文件夹中的虚拟目录的正确物理路径 - Server.MapPath does not return the right physical path mapped to a virtual directory in Web-App subfolder 在MVC3中使用Server.MapPath - Using Server.MapPath in MVC3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM