Skip to content

Instantly share code, notes, and snippets.

@davidfowl
Created September 5, 2017 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidfowl/6bd505256ddc95e0b70fdfa4569c6e9e to your computer and use it in GitHub Desktop.
Save davidfowl/6bd505256ddc95e0b70fdfa4569c6e9e to your computer and use it in GitHub Desktop.
IIS integration with IPV4 only
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