Метод ASP MapPath
❮ Полный справочник серверных объектов
Метод MapPath сопоставляет указанный путь с физическим путем.
Примечание. Этот метод нельзя использовать в Session.OnEnd и Application.OnEnd.
Синтаксис
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 |
Примеры
Пример 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>")
%>
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
Пример 2
Как использовать относительный путь, чтобы вернуть относительный физический путь к просматриваемой в браузере странице:
<%
response.write(Server.MapPath("../"))
%>
or
<%
response.write(Server.MapPath("..\"))
%>
❮ Полный справочник серверных объектов