Método MapPath ASP
MapPath método para especificar la ruta asigna a la ruta física correspondiente en el servidor.
Nota: Este método no se puede utilizar en Session.OnEnd y Application.OnEnd.
gramática
Server.MapPath(path)
参数 | 描述 |
---|---|
path | 必需。映射为物理路径的相对路径或绝对路径。如果该参数以 / 或 \ 开头,则返回完整的虚拟路径。如果该参数不以 / 或 \ 开头,则返回相对于正在被处理的 .asp 文件的路径。 |
Ejemplos
Ejemplo 1
Por ejemplo, el test.asp archivo que se encuentra en C: \ Inetpub \ wwwroot \ Script.
Test.ASP archivo (que se encuentra en el directorio C: \ Inetpub \ wwwroot \ Script) contiene el siguiente código:
<%
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
Ejemplo 2
Cómo utilizar una ruta relativa para volver a llegar a la ruta física relativa se ve en el navegador la página:
<%
response.write(Server.MapPath("../"))
%>
或者:
<%
response.write(Server.MapPath(".."))
%>
response.write(Server.MapPath("../"))
%>
或者:
<%
response.write(Server.MapPath(".."))
%>
Referencia completa de objetos de servidor