HttpRequest.ApplicationPath Property

Gets the ASP.NET application's virtual application root path on the server.

Namespace: System.Web
Assembly: System.Web (in system.web.dll)

public string ApplicationPath { get; }
/** @property */
public String get_ApplicationPath ()

public function get ApplicationPath () : String

Not applicable.

Property Value

The virtual path of the current application.

Use this property to construct a URL relative to the application root from a page or Web user control that is not in the root directory. This allows pages and shared controls that exist at different levels of a directory structure to use the same code to link to resources at fixed locations in the application.

The following example uses the Write method to HTML-encode and then write the value of the ApplicationPath property to a text file. This code example is part of a larger example provided for the HttpRequest class. It assumes the existence of a StreamWriter object named sw.

// Write request information to the file with HTML encoding.

The following example uses the ApplicationPath property to programmatically construct a path to a resource that is in a fixed location in the application. The page that references the resource does not have to be located in the same directory as the resource.

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<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;
        Label3.Text = Request.AppRelativeCurrentExecutionFilePath;
        if (VirtualPathUtility.GetDirectory(
            Image2.ImageUrl = Request.ApplicationPath +
            Image2.ImageUrl = Request.ApplicationPath +
        Label4.Text = Image2.ImageUrl;

<html xmlns="" >
<head runat="server">
    <title>HttpRequest.ApplicationPath Example</title>
    <form id="form1" runat="server">
        This is the ApplicationPath from the current page:<br />
        <asp:Label ID="Label1" runat="server" ForeColor="Brown" /><br />
        Use it to link to a centralized resource from an unknown location.<br />
        <asp:Image ID="Image1" runat="server" />
        <asp:Label ID="Label2" runat="server" ForeColor="Brown" />
        <br /><br />
        This is the AppRelativeCurrentExecutionFilePath to the current page:<br />
        <asp:Label ID="Label3" runat="server" ForeColor="Brown" /><br />
        Use it to programatically access URL information across multiple 
        deployments.<br />
        <asp:Image ID="Image2" runat="server" />
        <asp:Label ID="Label4" runat="server" ForeColor="Brown" />

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions