Thursday, November 1, 2007

Resolve relative url's without ResolveUrl

Sometimes you need to resolve relative url's without ResolveUrl. If the code is executing outside a Control, for example in an IHttpHandler or business layer code somewhere that has no reference to a Control, you can't call Control.ResolveUrl.

The System.Web.VirtualPathUtility class has some very useful method for converting from an app relative path to an absolute path:

string absoluteUrl = VirtualPathUtility.ToAbsolute(relativeUrl);

No comments: