ASP วิธี MapPath
วิธี MapPath เพื่อระบุเส้นทางที่แมปไปยังเส้นทางกายภาพที่สอดคล้องกันบนเซิร์ฟเวอร์
หมายเหตุ: วิธีการนี้ไม่สามารถนำมาใช้ใน Session.OnEnd และ Application.OnEnd
ไวยากรณ์
Server.MapPath(path)
参数 | 描述 |
---|---|
path | 必需。映射为物理路径的相对路径或绝对路径。如果该参数以 / 或 \ 开头,则返回完整的虚拟路径。如果该参数不以 / 或 \ 开头,则返回相对于正在被处理的 .asp 文件的路径。 |
ตัวอย่าง
ตัวอย่างที่ 1
ยกตัวอย่างเช่น Test.asp ไฟล์อยู่ใน C: \ Inetpub \ Wwwroot \ สคริปต์
ไฟล์ Test.asp (อยู่ใน C: \ Inetpub \ Wwwroot \ สคริปต์) มีรหัสต่อไปนี้:
<%
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
ตัวอย่างที่ 2
วิธีการใช้เส้นทางสัมพันธ์ที่จะกลับไปถึงเส้นทางกายภาพญาติถูกมองในเบราว์เซอร์หน้า:
<%
response.write(Server.MapPath("../"))
%>
或者:
<%
response.write(Server.MapPath(".."))
%>
response.write(Server.MapPath("../"))
%>
或者:
<%
response.write(Server.MapPath(".."))
%>
อ้างอิงวัตถุสมบูรณ์เซิร์ฟเวอร์