Mike-Ward.Net

Resolving Virtual Paths to Uri's in ASP.Net

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?

← newer older →
.Net, Technology, Life, Whatever

Recent Posts

Quick Tip - Clear ReSharper's Cache to Fix False Errors
Quick Tip - Refined GitHub
Vertical Layout for HTML Tables
Visual Studio 2017 Installer Quick Tip
VSColorOutput for VS 2017 Released
Quick ReSharper tip for inline templates
NoSQL vs. NewSQL: What's the Difference?
More... (1077)

Donate with PayPal