Skip to content

Instantly share code, notes, and snippets.

@Stephanvs
Created February 23, 2012 20:46
Show Gist options
  • Save Stephanvs/1894955 to your computer and use it in GitHub Desktop.
Save Stephanvs/1894955 to your computer and use it in GitHub Desktop.
Url Helper for ASP.NET MVC hosted on AppHarbor
public static string ToPublicUrl(this UrlHelper urlHelper, Uri relativeUri)
{
var httpContext = urlHelper.RequestContext.HttpContext;
var uriBuilder = new UriBuilder
{
Host = httpContext.Request.Url.Host,
Path = "/",
Port = 80,
Scheme = "http",
};
if (httpContext.Request.IsLocal)
{
uriBuilder.Port = httpContext.Request.Url.Port;
}
return new Uri(uriBuilder.Uri, relativeUri).AbsoluteUri;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment