Latest web development tutorials

ASP metodo MapPath

Server Object Reference Completa Server Object Reference

metodo MapPath per specificare il percorso mappato al corrispondente percorso fisico sul server.

Nota: Questo metodo non può essere utilizzato in Session.OnEnd e Application.OnEnd.

grammatica

Server.MapPath(path)

参数 描述
path 必需。映射为物理路径的相对路径或绝对路径。如果该参数以 / 或 \ 开头,则返回完整的虚拟路径。如果该参数不以 / 或 \ 开头,则返回相对于正在被处理的 .asp 文件的路径。

Esempi

esempio 1

Ad esempio, il Test.asp file che si trova in C: \ Inetpub \ wwwroot \ Script.

File Test.asp (che si trova nella cartella C: \ Inetpub \ wwwroot \ Script) contiene il seguente codice:

<%
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

esempio 2

Come utilizzare un percorso relativo per tornare a raggiungere il percorso fisico relativo viene visualizzato nel browser la pagina:

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

或者:

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


Server Object Reference Completa Server Object Reference