in

vbCity Blogs

New (temp) place for vbCity Blogs

Serge B. Blog

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

There are times you need to resolver relative URL like "~/my/link.aspx" into ablsolute 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.

Only published comments... Jan 21 2009, 02:35 PM by Serge B.
Filed under: , , ,
Copyright 1998-2009 vbCity.com LLC
Powered by Community Server (Non-Commercial Edition), by Telligent Systems