Latest web development tutorials

ASP MapPath Method

Server Object Reference Complete Server Object Reference

MapPath method to specify the path mapped to the corresponding physical path on the server.

Note: This method can not be used in Session.OnEnd and Application.OnEnd.

grammar

Server.MapPath(path)

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

Examples

Example 1

For example, the file test.asp located in C: \ Inetpub \ wwwroot \ Script.

File Test.asp (located in the C: \ Inetpub \ wwwroot \ Script) contains the following code:

<%
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

Example 2

How to Use a relative path to return to reach the relative physical path is viewed in the browser the page:

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

或者:

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


Server Object Reference Complete Server Object Reference