HttpRequest.ApplicationPath 속성

정의

ASP.NET 애플리케이션의 가상 애플리케이션 루트 경로를 서버에서 가져옵니다.

public:
 property System::String ^ ApplicationPath { System::String ^ get(); };
public string ApplicationPath { get; }
member this.ApplicationPath : string
Public ReadOnly Property ApplicationPath As String

속성 값

String

현재 애플리케이션의 가상 경로입니다.

예제

다음 예제에서는 메서드를 Write 사용하여 HTML 인코딩한 다음 속성 값을 ApplicationPath 텍스트 파일에 씁니다. 이 코드 예제는에 대해 제공 된 큰 예제의 일부는 HttpRequest 클래스입니다. 라는 sw개체가 StreamWriter 있다고 가정합니다.

// Write request information to the file with HTML encoding.
sw.WriteLine(Server.HtmlEncode(DateTime.Now.ToString()));
sw.WriteLine(Server.HtmlEncode(Request.CurrentExecutionFilePath));
sw.WriteLine(Server.HtmlEncode(Request.ApplicationPath));
sw.WriteLine(Server.HtmlEncode(Request.FilePath));
sw.WriteLine(Server.HtmlEncode(Request.Path));
' Write request information to the file with HTML encoding.
sw.WriteLine(Server.HtmlEncode(DateTime.Now.ToString()))
sw.WriteLine(Server.HtmlEncode(Request.CurrentExecutionFilePath))
sw.WriteLine(Server.HtmlEncode(Request.ApplicationPath))
sw.WriteLine(Server.HtmlEncode(Request.FilePath))
sw.WriteLine(Server.HtmlEncode(Request.Path))

다음 예제에서는 ApplicationPath 속성을 프로그래밍 방식으로 애플리케이션에서 고정된 된 위치에 있는 리소스에 대 한 경로 생성 합니다. 리소스를 참조하는 페이지는 리소스와 동일한 디렉터리에 있을 필요가 없습니다.

<%@ 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)
    {
        Label1.Text = Request.ApplicationPath;
        Image1.ImageUrl = Request.ApplicationPath + "/images/Image1.gif";
        Label2.Text = Image1.ImageUrl;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>HttpRequest.ApplicationPath Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        ApplicationPath:<br />
        <asp:Label ID="Label1" runat="server" ForeColor="Brown" /><br />

        <asp:Image ID="Image1" runat="server" /><br />

        ImageUrl:<br />
        <asp:Label ID="Label2" runat="server" ForeColor="Brown" />
        <br />
        </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)
        Label1.Text = Request.ApplicationPath
        Image1.ImageUrl = Request.ApplicationPath + "/images/Image1.gif"
        Label2.Text = Image1.ImageUrl
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>HttpRequest.ApplicationPath Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        ApplicationPath:<br />
        <asp:Label ID="Label1" runat="server" ForeColor="Brown" /><br />

        <asp:Image ID="Image1" runat="server" />

        ImageUrl:<br />
        <asp:Label ID="Label2" runat="server" ForeColor="Brown" />
        <br />
     </div>
    </form>
</body>
</html>

WebSite1, 이라고 하는 웹 애플리케이션이 예제를 실행 하는 경우 /WebSite1 의 값으로 표시 됩니다는 ApplicationPath 속성 및 /WebSite1/images/Image1.gif 이미지의 전체 경로로 표시 됩니다.

설명

이 속성을 사용 하 여 페이지 또는 루트 디렉터리에 있지 않은 웹 사용자 정의 컨트롤에서 애플리케이션 루트를 기준으로 URL을 생성 합니다. 이렇게 하면 다른 수준의 디렉터리 구조가 동일한 코드를 사용 하 여 애플리케이션에서 고정 된 위치에서 리소스에 연결할 수 있는 공유 컨트롤과 페이지 수 있습니다.

적용 대상