Within the context of a web application:
<filename> will match "filename" in the same directory context (i.e. a sibling file that resides in the same directory).
/ will always get you back to the root of the WEB SERVER. It's important to understand that its the SERVER root, not just the APPLICATION root. Therefore, starting from here:
http://myserver/myapp/directory/page.aspx
a reference to "/anotherpage.aspx" would give you
http://myserver/anotherpage.aspx
./ is equal to no prefix at all ("." references the current location):
<filename> == ./<filename>
../ will get you BACK one directory. Therefore, starting from here:
http://myserver/myapp/directory/page.aspx
a reference to "../anotherpage.aspx" would give you
http://myserver/myapp/anotherpage.aspx
When you are dealing with a URL type property or method in an ASP.NET page/control you can use the ~ character to reference the application root. That way you can make APPLICATION ROOT relative references without the worry that a different virtual directory name will mess things up.
In a web application directory (virtual directory) called "myapp", with a reference such as this: "~/<resource>" ~ will sometimes resolve to something like "/myapp/<resource>" or sometimes "../<resource>". I've seen it happen both ways.
.NET properties and methods that observe the expectant behavior of the ~ character are, among others:
System.Web.UI.WebControls.Hyperlink.NavigateUrl
System.Web.UI.WebControls.Image.ImageUrl
System.Web.UI.Page.ResolveUrl
System.Web.HttpServerUtility.MapPath
Using this technique is greatly beneficial when you have a complex development environment with different developers and many deployment environments where the name of the virtual directory hosting the application may be different or there may not be one at all. For example:
App in local development (IIS):
http://localhost/myapp
App in local development (VS2005 server):
http://localhost:12345/
App in test environment:
http://www.mycompany.com/staging/myapp
App in production:
http://myapp.mycompany.com
-
Peter