ASP Metode MapPath
Metode MapPath untuk menentukan path dipetakan ke jalur fisik yang sesuai pada server.
Catatan: Metode ini tidak dapat digunakan di Session.OnEnd dan Application.OnEnd.
tatabahasa
Server.MapPath(path)
参数 | 描述 |
---|---|
path | 必需。映射为物理路径的相对路径或绝对路径。如果该参数以 / 或 \ 开头,则返回完整的虚拟路径。如果该参数不以 / 或 \ 开头,则返回相对于正在被处理的 .asp 文件的路径。 |
contoh
contoh 1
Sebagai contoh, test.asp file yang terletak di C: \ Inetpub \ wwwroot \ Script.
Berkas Test.asp (terletak di C: \ Inetpub \ wwwroot \ Script) berisi kode berikut:
<%
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
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
contoh 2
Cara Menggunakan path relatif untuk kembali mencapai jalur fisik relatif dilihat di browser halaman:
<%
response.write(Server.MapPath("../"))
%>
或者:
<%
response.write(Server.MapPath(".."))
%>
response.write(Server.MapPath("../"))
%>
或者:
<%
response.write(Server.MapPath(".."))
%>
Lengkap Server Object Reference