Welcome to CrankyGoblin.Com Sign in | Join | Help

Public Class GeoffAppleby

Inherits Microsoft.VisualBasic.MVP : Implements IBrainFart
Quick Virtual Path Tip

In ASP.net server controls you can specify page addresses using the tilde (~) character to specify a path from the root of the current web application.

Imagine you have a site mounted on your local machine under a virtual directory called 'foo'. To access the homepage, you would go to http://localhost/foo/default.aspx. In a server control within the site, I could reference '~/default.aspx' to link to the home page, but I can't write that out as a URL - the magic of server controls in ASP.net transforms the virtual path to the correct url.

The neat thing about this is that then the same site could be mounted under a different virtual directory (or at the root of the site) and ASP.net would still translate it directly.

But what if you aren't inside a server control but want to do the same thing?

In the above example, we can do this:

System.Web.VirtualPathUtility.ToAbsolute("~/default.aspx")

The returned string from this method is '/foo/default.aspx'. w00t!

Posted: Wednesday, November 15, 2006 7:47 PM by Geoff Appleby
Filed under: , ,

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required) 

To submit your comment, click on these pictures:
  • Super Geoff!
  • Geoff's little sister's pussy
  • Geoff the big mouth
Gaptcha Image - No Peeking! Gaptcha Image - No Peeking! Gaptcha Image - No Peeking!
Gaptcha Image - No Peeking! Gaptcha Image - No Peeking! Gaptcha Image - No Peeking!
Gaptcha Image - No Peeking! Gaptcha Image - No Peeking! Gaptcha Image - No Peeking!
Can't recognise the people in these pictures? Look here for a quick introduction.
There's a time limit for you to get your comment submitted before this set of pictures expires. If you think it's been longer than 10 minutes, get some new pictures first (you won't lose what you've typed so far).
Get some new pictures 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS