ASP。NET路径说明

属性 说明
ApplicationPath
获取当前应用程序的根目录路径,无论在该应用程序中的什么位置请求该路径。对于此示例,该属性将返回以下内容:

/

CurrentExecutionFilePath
获取当前请求的虚拟路径。不同于 FilePath,差别在于如果请求已在服务器代码中被重定向,则 CurrentExecutionFilePath 就是正确的。对于此示例,该属性将返回以下内容:

/MyApplication/MyPages/Default.aspx

如果作为对 Transfer 或 Execute 进行调用的结果,您获取正在运行的代码中的属性,则路径将反映该代码的位置。

FilePath
获取当前请求的虚拟路径。对于此示例,该属性将返回以下内容:

/MyApplication/MyPages/Default.aspx

不同于 CurrentExecutionFilePath,FilePath 不反映服务器端转换。

Path
获取当前请求的虚拟路径。对于此示例,该属性将返回以下内容:

/MyApplication/MyPages/default.aspx

PhysicalApplicationPath
获取当前正在执行的应用程序的根目录的物理文件系统路径。对于此示例,该属性将返回以下内容:

C:\inetpub\wwwroot\

PhysicalPath
获取与请求的 URL 对应的物理文件系统路径。对于此示例,该属性将返回以下内容:

C:\inetpub\wwwroot\MyApplication\MyPages\default.aspx

使用 MapPath 方法
MapPath 方法返回传递给该方法的虚拟路径的完整物理路径。例如,以下代码返回网站根目录的文件路径:

Visual Basic
复制代码
Dim rootPath As String = Server.MapPath("~")

C#
复制代码
String rootPath = Server.MapPath("~");

注意
传递给 MapPath 方法的路径必须为应用程序相对路径,而不是绝对路径。

posted @ 2009-06-10 14:45  XGU_Winner  阅读(169)  评论(0编辑  收藏  举报