Server.MapPath (“.”), Server.MapPath (“~”), Server.MapPath (@“\”), Server.MapPath (“/”). 차이점은 무엇입니까?
사람 사이의 차이를 설명 할 수 Server.MapPath("."), Server.MapPath("~"), Server.MapPath(@"\")와 Server.MapPath("/")?
Server.MapPath 는 실제 디렉토리 에 매핑 할 상대 또는 가상 경로를 지정합니다 .
Server.MapPath(".")1 은 실행중인 파일의 현재 실제 디렉토리 (예 : aspx)를 반환합니다Server.MapPath("..")부모 디렉토리를 반환Server.MapPath("~")응용 프로그램의 루트에 대한 실제 경로를 반환합니다Server.MapPath("/")도메인 이름의 루트에 대한 실제 경로를 반환합니다 (응용 프로그램의 루트와 반드시 같을 필요는 없음).
예를 들면 :
웹 사이트 응용 프로그램 ( http://www.example.com/)을
C:\Inetpub\wwwroot
상점 응용 프로그램 (서브 웹을 IIS에서 가상 디렉토리로, 응용 프로그램으로 표시됨)에 설치했습니다.
D:\WebApps\shop
예를 들어 Server.MapPath()다음 요청을하는 경우 :
http://www.example.com/shop/products/GetProduct.aspx?id=2342
그때:
Server.MapPath(".")1 반환D:\WebApps\shop\productsServer.MapPath("..")보고D:\WebApps\shopServer.MapPath("~")보고D:\WebApps\shopServer.MapPath("/")보고C:\Inetpub\wwwrootServer.MapPath("/shop")보고D:\WebApps\shop
Path가 슬래시 ( /) 또는 백 슬래시 ( \) MapPath()로 시작하면 경로가 전체 가상 경로 인 것처럼 경로를 반환합니다.
Path가 슬래시로 시작하지 않으면 MapPath()처리중인 요청의 디렉토리에 상대적인 경로를 리턴합니다.
참고 : C #에서 @문자열 그대로의 리터럴 문자열 연산자는 문자열을 "있는 그대로"사용해야하며 이스케이프 시퀀스를 처리하지 않아야한다는 의미입니다.
각주
Server.MapPath(null)그리고Server.MapPath("")것 도이 효과를 .
@splattne의 답변을 약간 확장하면됩니다.
MapPath(string virtualPath) 다음을 호출합니다.
public string MapPath(string virtualPath)
{
return this.MapPath(VirtualPath.CreateAllowNull(virtualPath));
}
MapPath(VirtualPath virtualPath)차례로 MapPath(VirtualPath virtualPath, VirtualPath baseVirtualDir, bool allowCrossAppMapping)다음을 포함하는 호출 :
//...
if (virtualPath == null)
{
virtualPath = VirtualPath.Create(".");
}
//...
따라서 MapPath(null)또는 MapPath("")에 전화 하면 효과적으로 전화하는 것입니다MapPath(".")
1) Server.MapPath(".")- aspx실행중인 파일의 "Current Physical Directory"를 반환합니다 (예 :).
전의. 가정D:\WebApplications\Collage\Departments
2) Server.MapPath("..")- "부모 디렉토리"를 반환
전의. D:\WebApplications\Collage
3) Server.MapPath("~")- "응용 프로그램 루트에 대한 물리적 경로"를 반환합니다.
전의. D:\WebApplications\Collage
4) Server.MapPath("/")-도메인 이름의 루트에 대한 물리적 경로를 반환합니다
전의. C:\Inetpub\wwwroot
'Programming' 카테고리의 다른 글
| CSS를 사용하여 텍스트 길이를 n 줄로 제한 (0) | 2020.02.17 |
|---|---|
| 배치 파일 내부에서 파일이 존재하는지 확인하는 방법 (0) | 2020.02.17 |
| RVM을 제거하는 방법? (0) | 2020.02.17 |
| 기존 Git 저장소를 다른 저장소로 가져 오는 방법은 무엇입니까? (0) | 2020.02.17 |
| 배쉬에서 숫자 비교 (0) | 2020.02.17 |