Created
September 5, 2017 17:44
-
-
Save davidfowl/6bd505256ddc95e0b70fdfa4569c6e9e to your computer and use it in GitHub Desktop.
IIS integration with IPV4 only
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 class WebHostBuilderIISExtensions | |
{ | |
private static readonly string ServerPort = "PORT"; | |
public static IWebHostBuilder UseIISIntegrationOnIpv4Only(this IWebHostBuilder webHostBuilder) | |
{ | |
var port = webHostBuilder.GetSetting(ServerPort) ?? Environment.GetEnvironmentVariable($"ASPNETCORE_{ServerPort}"); | |
var address = "http://127.0.0.1:" + port; | |
return webHostBuilder.UseIISIntegration() | |
.ConfigureServices(services => | |
{ | |
// This is delayed until ConfigureServices since that's what UseIISIntegration does and | |
// we need to override it | |
webHostBuilder.UseSetting(WebHostDefaults.ServerUrlsKey, address); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment