MapPath

收藏:0   阅读:24

ASP MapPath 方法


MapPath 方法可把指定的路径映射到服务器上相应的物理路径上。

注意:此方法不能用于 Session.OnEnd 和 Application.OnEnd 中。

语法

Server.MapPath(path)

参数 描述
path 必需。映射为物理路径的相对路径或绝对路径。如果该参数以 / 或 \ 开头,则返回完整的虚拟路径。如果该参数不以 / 或 \ 开头,则返回相对于正在被处理的 .asp 文件的路径。

实例

实例 1

举例,文件 test.asp 位于 C:\Inetpub\wwwroot\Script。

文件 Test.asp (位于 C:\Inetpub\wwwroot\Script) 包含下列代码:

<%
response.write(Server.MapPath("test.html") & "<br>")
response.write(Server.MapPath("script/test.html") & "<br>")
response.write(Server.MapPath("/script/test.html") & "<br>")
response.write(Server.MapPath("script") & "<br>")
response.write(Server.MapPath("/") & "<br>")
response.write(Server.MapPath("") & "<br>")
%>

输出:

c:inetpubwwwrootscripttest.html
c:inetpubwwwrootscriptscripttest.html
c:inetpubwwwrootscripttest.html
c:inetpubwwwrootscript
c:inetpubwwwroot
c:inetpubwwwroot

实例 2

如何使用一个相对路径来返回到达正在浏览器中查看的页面的相对物理路径:

<%
response.write(Server.MapPath("../"))
%>

或者:

<%
response.write(Server.MapPath(".."))
%>
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!