diff --git a/src/Microsoft.AspNetCore.Server.IISIntegration/WebHostBuilderIISExtensions.cs b/src/Microsoft.AspNetCore.Server.IISIntegration/WebHostBuilderIISExtensions.cs index ae6a336979..6f7f977c13 100644 --- a/src/Microsoft.AspNetCore.Server.IISIntegration/WebHostBuilderIISExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.IISIntegration/WebHostBuilderIISExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -52,6 +52,7 @@ namespace Microsoft.AspNetCore.Hosting { // Delay register the url so users don't accidently overwrite it. hostBuilder.UseSetting(WebHostDefaults.ServerUrlsKey, address); + hostBuilder.PreferHostingUrls(true); services.AddSingleton(new IISSetupFilter(pairingToken, new PathString(path))); services.Configure(options => { diff --git a/test/Microsoft.AspNetCore.Server.IISIntegration.Tests/IISMiddlewareTests.cs b/test/Microsoft.AspNetCore.Server.IISIntegration.Tests/IISMiddlewareTests.cs index ea1be889e5..9be4aa590f 100644 --- a/test/Microsoft.AspNetCore.Server.IISIntegration.Tests/IISMiddlewareTests.cs +++ b/test/Microsoft.AspNetCore.Server.IISIntegration.Tests/IISMiddlewareTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Net; @@ -72,7 +72,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration } [Fact] - public void UrlDelayRegistered() + public void UrlDelayRegisteredAndPreferHostingUrlsSet() { var builder = new WebHostBuilder() .UseSetting("TOKEN", "TestToken") @@ -85,11 +85,13 @@ namespace Microsoft.AspNetCore.Server.IISIntegration }); Assert.Null(builder.GetSetting(WebHostDefaults.ServerUrlsKey)); + Assert.Null(builder.GetSetting(WebHostDefaults.PreferHostingUrls)); // Adds a server and calls Build() var server = new TestServer(builder); Assert.Equal("http://localhost:12345", builder.GetSetting(WebHostDefaults.ServerUrlsKey)); + Assert.Equal("true", builder.GetSetting(WebHostDefaults.PreferHostingUrls)); } [Fact]