«
Friday Links #27 |
Managing Money – Rule #2 »
ASP.Net has a boat load of methods for dealing with paths. However, no where can I find a method to convert a virtual path (~/) to its equivalent Uri. Perhaps it’s there but darn if I can find it. The best I can up with is:
var uri = Request.Url.GetLeftPart(UriPartial.Authority) + ResolveUrl("~/SomePage.aspx")
If the site is hosted at: http://example.com/website, then this code yields http://example.com/website/SomePage.aspx, which is what I want.

Perhaps there is a better way to do this?
Comments
RE: Resolving Virtual Paths to Uri's in ASP.Net
by Stephen
Friday, December 19, 2008 5:29 PM
I think this is one of the better ways to accomplish Virtual Path String to URI conversion. Thanks so much for your post.
RE: Resolving Virtual Paths to Uri's in ASP.Net
by Mike
Friday, December 19, 2008 5:58 PM
Stephen,
Thanks for the feedback. No one as suggested an existing API so maybe one does not exist.
RE: Resolving Virtual Paths to Uri's in ASP.Net
by Yoann. B
Saturday, December 20, 2008 1:24 PM
Hi,
Maybe this could help :
public static String ToBaseAbsolute(this Uri uri)
{
return String.Format("{0}://{1}", uri.Scheme, uri.Authority);
}
Yoann,
powered by Bloget™