Jean-Marc Amiaud

Getting the absolute path in ASP.NET

by on Nov.30, 2010, under ASP.NET

After too much case of context, i´ve wrote a simple but powerfull function to get the absolute path in ASP.NET.
[code lang= »csharp »]

public static string GetAbsoluteUrl(string relativeUrl)
return String.Format("{0}://{1}{2}{3}",
HttpContext.Current.Request.IsSecureConnection ? "https" : "http",
HttpContext.Current.Request.Url.IsDefaultPort ? "" : ":" + HttpContext.Current.Request.Url.Port,
VirtualPathUtility.ToAbsolute(relativeUrl, HttpRuntime.AppDomainAppVirtualPath));


Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!