VirtualPathUtility 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
일반적인 가상 경로 작업에 대한 유틸리티 메서드를 제공합니다.
public ref class VirtualPathUtility abstract sealed
public static class VirtualPathUtility
type VirtualPathUtility = class
Public Class VirtualPathUtility
- 상속
-
VirtualPathUtility
예제
다음 코드 예제에서는 클래스 및 일부 메서드를 VirtualPathUtility 사용하는 방법을 보여 줍니다. 먼저 이 속성은 FilePath 웹 페이지에 대한 가상 경로를 생성합니다. , GetExtension및 GetDirectory 메서드는 GetFileName가상 경로에 대한 정보를 반환합니다. 다음으로, CurrentExecutionFilePath 메서드가 호출된 경우 Redirect 속성과 다를 수 있는 현재 요청의 FilePath 가상 경로를 생성합니다. , IsAppRelative및 ToAppRelative 메서드는 IsAbsolute가상 경로에 대한 정보를 반환합니다.
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
// <Snippet2>
StringBuilder sb = new StringBuilder();
String pathstring = Context.Request.FilePath.ToString();
sb.Append("Current file path = " + pathstring + "<br />");
sb.Append("File name = " + VirtualPathUtility.GetFileName(pathstring).ToString() + "<br />");
sb.Append("File extension = " + VirtualPathUtility.GetExtension(pathstring).ToString() + "<br />");
sb.Append("Directory = " + VirtualPathUtility.GetDirectory(pathstring).ToString() + "<br />");
Response.Write(sb.ToString());
// </Snippet2>
// <Snippet3>
StringBuilder sb2 = new StringBuilder();
String pathstring1 = Context.Request.CurrentExecutionFilePath.ToString();
sb2.Append("Current Executing File Path = " + pathstring1.ToString() + "<br />");
sb2.Append("Is Absolute = " + VirtualPathUtility.IsAbsolute(pathstring1).ToString() + "<br />");
sb2.Append("Is AppRelative = " + VirtualPathUtility.IsAppRelative(pathstring1).ToString() + "<br />");
sb2.Append("Make AppRelative = " + VirtualPathUtility.ToAppRelative(pathstring1).ToString() + "<br />");
Response.Write(sb2.ToString());
// </Snippet3>
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>VirtualPathUtility Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
' <Snippet2>
Dim sb As New StringBuilder()
Dim pathstring As String = Context.Request.FilePath.ToString()
sb.Append("Current file path = " & pathstring & "<br />")
sb.Append("File name = " & VirtualPathUtility.GetFileName(pathstring).ToString() & "<br />")
sb.Append("File extension = " & VirtualPathUtility.GetExtension(pathstring).ToString() & "<br />")
sb.Append("Directory = " & VirtualPathUtility.GetDirectory(pathstring).ToString() & "<br />")
Response.Write(sb.ToString())
' </Snippet2>
' <Snippet3>
Dim sb2 As New StringBuilder()
Dim pathstring1 As String = Context.Request.CurrentExecutionFilePath.ToString()
sb2.Append("Current Executing File Path = " & pathstring1.ToString() & "<br />")
sb2.Append("Is Absolute = " & VirtualPathUtility.IsAbsolute(pathstring1).ToString() & "<br />")
sb2.Append("Is AppRelative = " & VirtualPathUtility.IsAppRelative(pathstring1).ToString() & "<br />")
sb2.Append("Make AppRelative = " & VirtualPathUtility.ToAppRelative(pathstring1).ToString() & "<br />")
Response.Write(sb2.ToString())
' </Snippet3>
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>VirtualPathUtility Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
설명
이 클래스는 VirtualPathUtility 가상 경로와 관련된 일반적인 작업에 대한 유틸리티 메서드를 제공합니다. ASP.NET 서버 컨트롤 및 서버 코드의 경우 웹 애플리케이션 루트 연산자를 사용하는 가상 경로인 타일(~)은 일반적으로 상대 및 절대 경로 대신 사용됩니다. 자세한 내용은 ASP.NET 웹 프로젝트 경로를 참조하세요.
VirtualPathUtility 사용자 지정 웹 서비스 처리기를 개발하는 경우처럼 애플리케이션 상대 경로를 절대 가상 경로로 변환해야 하는 경우 클래스를 사용합니다.
절대 가상 경로는 리터럴 슬래시 표시(/)로 시작합니다. 상대 가상 경로는 타일(~)일 뿐이거나 타일과 이중 백슬래시(~\\) 또는 타일과 슬래시 표시(~/)로 시작하는 경우 애플리케이션 루트 디렉터리를 기준으로 합니다. 가상 경로를 상대적으로 만들면 경로가 애플리케이션과 독립적입니다.
애플리케이션에 대한 가상 디렉터리를 및 ApplicationPath 속성에서 AppDomainAppVirtualPath 가져올 수 있습니다.
메모
클래스는 VirtualPathUtility 보안 또는 정식화를 위한 것이 아닙니다. 웹 애플리케이션 보안에 대한 자세한 내용은 웹 애플리케이션 보안 위협 개요를 참조하세요. 일반 URL 처리 기능은 다음을 참조하세요 Uri.
메서드
| Name | Description |
|---|---|
| AppendTrailingSlash(String) |
가상 경로가 아직 없는 경우 리터럴 슬래시 표시(/)를 가상 경로의 끝에 추가합니다. |
| Combine(String, String) |
기본 경로와 상대 경로를 결합합니다. |
| GetDirectory(String) |
가상 경로의 디렉터리 부분을 반환합니다. |
| GetExtension(String) |
가상 경로에서 참조되는 파일의 확장자를 검색합니다. |
| GetFileName(String) |
가상 경로에서 참조되는 파일의 파일 이름을 검색합니다. |
| IsAbsolute(String) |
지정된 가상 경로가 절대 경로인지 여부를 나타내는 부울 값을 반환합니다. 즉, 리터럴 슬래시 표시(/)로 시작합니다. |
| IsAppRelative(String) |
지정된 가상 경로가 애플리케이션을 기준으로 하는지 여부를 나타내는 부울 값을 반환합니다. |
| MakeRelative(String, String) |
루트 연산자(타일드 [~])가 포함된 한 가상 경로에서 다른 가상 경로로의 상대 가상 경로를 반환합니다. |
| RemoveTrailingSlash(String) |
가상 경로에서 후행 슬래시 표시(/)를 제거합니다. |
| ToAbsolute(String, String) |
지정된 애플리케이션 경로를 사용하여 가상 경로를 애플리케이션 절대 경로로 변환합니다. |
| ToAbsolute(String) |
가상 경로를 애플리케이션 절대 경로로 변환합니다. |
| ToAppRelative(String, String) |
지정된 애플리케이션 경로를 사용하여 가상 경로를 애플리케이션 상대 경로로 변환합니다. |
| ToAppRelative(String) |
속성에 있는 애플리케이션 가상 경로를 사용하여 가상 경로를 애플리케이션 상대 경로로 AppDomainAppVirtualPath 변환합니다. |