ASP MapPath 方法
完整的 Server 對(duì)象參考手冊(cè)
MapPath 方法可把指定的路徑映射到服務(wù)器上相應(yīng)的物理路徑上。
注意:此方法不能用于 Session.OnEnd 和 Application.OnEnd 中。
語(yǔ)法
參數(shù) | 描述 |
path | 必需。映射為物理路徑的相對(duì)路徑或絕對(duì)路徑。如果該參數(shù)以 / 或 \ 開頭,則返回完整的虛擬路徑。如果該參數(shù)不以 / 或 \ 開頭,則返回相對(duì)于正在被處理的 .asp 文件的路徑。 |
實(shí)例
實(shí)例 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
實(shí)例 2
如何使用一個(gè)相對(duì)路徑來(lái)返回到達(dá)正在瀏覽器中查看的頁(yè)面的相對(duì)物理路徑:
<%
response.write(Server.MapPath("../"))
%>
或者:
<%
response.write(Server.MapPath(".."))
%>
完整的 Server 對(duì)象參考手冊(cè)
更多建議: