Skip to content

Instantly share code, notes, and snippets.

@runesoerensen
Created January 30, 2011 22:49
Show Gist options
  • Save runesoerensen/803358 to your computer and use it in GitHub Desktop.
Save runesoerensen/803358 to your computer and use it in GitHub Desktop.
Builds a public URL when IIS is behind a load balancer
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