Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

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.asp") & "<br>")
response.write(Server.MapPath("script/test.asp") & "<br>")
response.write(Server.MapPath("/script/test.asp") & "<br>")
response.write(Server.MapPath("\script") & "<br>")
response.write(Server.MapPath("/") & "<br>")
response.write(Server.MapPath("\") & "<br>")
%>

输出

c:\inetpub\wwwroot\script\test.asp
c:\inetpub\wwwroot\script\script\test.asp
c:\inetpub\wwwroot\script\test.asp
c:\inetpub\wwwroot\script
c:\inetpub\wwwroot
c:\inetpub\wwwroot

示例 2

如何使用相对路径返回浏览器中正在查看的页面的相对物理路径

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



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

❮ 完整服务器对象参考
×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.