Metodo ASP MapPath


❮ Riferimento completo dell'oggetto server

Il metodo MapPath associa un percorso specificato a un percorso fisico.

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

Sintassi

Server.MapPath(path)

Parameter Description
path Required. A relative or virtual path to map to a physical path. If this parameter starts with / or \, it returns a path as if this parameter is a full virtual path. If this parameter doesn't start with / or \, it returns a path relative to the directory of the .asp file being processed

Esempi

Esempio 1

Per l'esempio seguente, il file "test.asp" si trova in C:\Inetpub\Wwwroot\Script.

Il file "test.asp" (che si trova in C:\Inetpub\Wwwroot\Script) contiene il codice seguente:

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

Output:

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

Esempio 2

Come utilizzare un percorso relativo per restituire il percorso fisico relativo alla pagina visualizzata nel browser:

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

or

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

❮ Riferimento completo dell'oggetto server