.NET Framework 类库
HttpServerUtility..::.MapPath 方法

更新:2007 年 11 月

返回与 Web 服务器上的指定虚拟路径相对应的物理文件路径。

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

语法

Visual Basic(声明)
Public Function MapPath ( _
    path As String _
) As String
Visual Basic (用法)
Dim instance As HttpServerUtility
Dim path As String
Dim returnValue As String

returnValue = instance.MapPath(path)
C#
public string MapPath(
    string path
)
Visual C++
public:
String^ MapPath(
    String^ path
)
J#
public String MapPath(
    String path
)
JScript
public function MapPath(
    path : String
) : String

参数

path
类型:System..::.String

Web 服务器的虚拟路径。

返回值

类型:System..::.String

path 相对应的物理文件路径。

异常

异常条件
HttpException

当前 HttpContextnullNothingnullptrnull 引用(在 Visual Basic 中为 Nothing

备注

如果 pathnullNothingnullptrnull 引用(在 Visual Basic 中为 NothingMapPath 方法将返回包含当前应用程序的目录的完整物理路径。

安全说明:

MapPath 方法很可能包含有关宿主环境的敏感信息。不应向用户显示返回值。

示例

下面的示例返回包含指定网站的虚拟目录的物理路径。若要读取代码隐藏模块中的 MapPath,请使用 HttpContext.Current.Server.MapPath

Visual Basic
Dim FilePath As String
FilePath = Server.MapPath("/MyWebSite")

C#
String FilePath;
FilePath = Server.MapPath("/MyWebSite");

J#
String filePath;
filePath = get_Server().MapPath("/MyWebSite");
JScript
var filePath : String = Server.MapPath("/MyWebSite")

平台

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求

版本信息

.NET Framework

受以下版本支持:3.5、3.0、2.0、1.1、1.0
另请参见

参考

标记 :


Page view tracker