asp.net的Server.MapPath方法

Server.MapPath()的功能:
返回与 Web 服务器上的指定虚拟路径相对应的物理文件路径。

命名空间: System.Web
程序集: System.Web(在 System.Web.dll 中)

public string MapPath(
 string path
)

其中参数path
类型:System.String
Web 服务器的虚拟路径。


返回值
类型:System.String
与 path 相对应的物理文件路径。

如果 path 为 null,MapPath 方法将返回包含当前应用程序的目录的完整物理路径。

安全说明
MapPath 方法很可能包含有关承载环境的敏感信息。 不应向用户显示返回值。

.NET Framework
受以下版本支持:4.543.53.02.01.11.0

例子:
Server.MapPath("")返回当前页面所在的文件夹的路径,如D:wwwrootKeleyiWebTest

Server.MapPath("/")返回站点的根目录D:wwwrootKeleyiWeb


Server.MapPath("./") :返回当前页面所在的物理文件路径:D:wwwrootKeleyiWebTest
Server.MapPath("../"):返回当前页面所在的上一级的物理文件夹路径:D:wwwrootKeleyiWeb
Server.MapPath("~/"):返回应用程序的虚拟目录(路径):D:wwwrootKeleyiWeb
Server.MapPath("~"):返回应用程序的虚拟目录(路径):D:wwwrootKeleyiWeb
 
原文地址:https://www.cnblogs.com/rwh871212/p/5332827.html