简体   繁体   English

Server.MapPath给出了错误的路径,在IIS服务器上运行时出现异常“不支持给定路径的格式”?

[英]Server.MapPath gives wrong path, exception “The given path's format is not supported” when running on IIS server?

Currently, I'm using the codes below to save a file to a directory on my website. 目前,我正在使用以下代码将文件保存到网站上的目录中。

//save the file to the server
String savePath = Server.MapPath("..\\temp\\") + file;
FileUpload.PostedFile.SaveAs(savePath);

When I'm running the application on my computer, it returns the path: 当我在计算机上运行应用程序时,它返回路径:

"E:\\dotnet\\Project\\Implementation\\Source Code\\Project\\Project.UI\\temp\\Sample.csv" “ E:\\ dotnet \\ Project \\ Implementation \\ Source Code \\ Project \\ Project.UI \\ temp \\ Sample.csv”

However, when running on a real server, it throws exception: 但是,在真实服务器上运行时,它将引发异常:

System.NotSupportedException: The given path's format is not supported.

The expected path that I would like to have is "C:\\inetpub\\wwwroot\\Project\\temp". 我希望拥有的预期路径是“ C:\\ inetpub \\ wwwroot \\ Project \\ temp”。

Am I doing things correctly or not? 我做的事正确与否吗? If not then can someone explain to me the correct way to do this? 如果不是,那么有人可以向我解释正确的方法吗?

Server.MapPath maps a virtual path to a physical one on the server. Server.MapPath将虚拟路径映射到服务器上的物理路径。 If you replace your backslashes with forward-slashes you should be ok: 如果将反斜杠替换为正斜杠,则应该可以:

Server.MapPath("../temp/")

You can also use the root relative path: 您还可以使用根相对路径:

Server.MapPath("~/temp/");

声明:本站的技术帖子网页,遵循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()返回与DirectoryInfo一起使用时不存在的路径 - Server.MapPath() returning a path that does not exist when used with DirectoryInfo 使用server.MapPath()时不允许使用相对虚拟路径 - Relative virtual path is not allowed when using server.MapPath() c# - 给定物理路径,Server.MapPath 中需要虚拟路径 - c# - Physical path given, virtual path expected in Server.MapPath Windows服务器不支持给定路径的格式 - The given path's format is not supported in windows server 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 c#使用Server.MapPath()找不到路径的一部分 - c# Could not find a part of the path with Server.MapPath() 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()?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM