In .NET server controls, any time you wish to reference a server resource (image, user control, another page) you can make use of the "~" character to act as the "home" placeholder. This will always reference the root of the current .NET web application. So if you have an images folder in the root of your web application (regardless of what the web application is named) you can always reference an image like this:
<asp:image imageurl="~/images/someimage.gif" />
No matter where this code falls on a page in any folder under the web application, you'll always end up with an image tag that looks like this:
<img src="/myWebApplication/images/someimage.gif">
Even if you put all the pages/images/code in a whole new application, the reference will be retained:
<img src="/myWholeNewAndDifferentWebApplication/images/someimage.gif">
You can use the same technique for creating links to other pages:
<asp:hyperlink navigateurl="~/somefolder/somepage.aspx">click me</asp:hyperlink>
results in:
<a href="/myWebApplication/somefolder/somepage.aspx">click me</a>
...or when registering user controls:
<%@ Register TagPrefix="uc" TagName="MyUserControl" Src="~/userControls/MyUserControl.ascx" %>
Also, the functionality that performs this home directory resolution is found on the Page class so you can access and utilize it anywhere in page code-behind:
ResolveUrl("~/someFolder/somePage.aspx")
|