Home » Technical

How to ResolveUrl() without Page context in ASP.NET

21 Jan 2009 by Serge B. 0 Comments

There are times you need to resolver relative URL like "~/my/link.aspx" into absolute and you don't want to use the Page context or can't easily access it.

Rick Strahl posted a great blog entry on ResolveUrl() without Page where he implements his own static ResolveUrl() method.

I found that System.Web namespace has method VirtualPathUtility.ToAbsolute that does exactly the trick.

You don't even need declare VirtualPathUtility class in VB for it is static.

 Dim _resolvedUrl As String = VirtualPathUtility.ToAbsolute("~/my/link.aspx")

And while you are on MSDN web site, feel free to explore other useful method of the System.Web.VirtualPathUtility class.

Bookmark and Share

Currently rated 2.0 by 2 people

  • Currently 2/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5