Created
January 30, 2011 22:49
-
-
Save runesoerensen/803358 to your computer and use it in GitHub Desktop.
Builds a public URL when IIS is behind a load balancer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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