diff --git a/src/Hosting/Abstractions/src/HostingAbstractionsWebHostBuilderExtensions.cs b/src/Hosting/Abstractions/src/HostingAbstractionsWebHostBuilderExtensions.cs
index f61b86eb86..1aac2e31d1 100644
--- a/src/Hosting/Abstractions/src/HostingAbstractionsWebHostBuilderExtensions.cs
+++ b/src/Hosting/Abstractions/src/HostingAbstractionsWebHostBuilderExtensions.cs
@@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Hosting
/// The .
public static IWebHostBuilder UseConfiguration(this IWebHostBuilder hostBuilder, IConfiguration configuration)
{
- foreach (var setting in configuration.AsEnumerable())
+ foreach (var setting in configuration.AsEnumerable(makePathsRelative: true))
{
hostBuilder.UseSetting(setting.Key, setting.Value);
}
diff --git a/src/Hosting/Hosting/test/WebHostBuilderTests.cs b/src/Hosting/Hosting/test/WebHostBuilderTests.cs
index 876959ddb4..5a9f280340 100644
--- a/src/Hosting/Hosting/test/WebHostBuilderTests.cs
+++ b/src/Hosting/Hosting/test/WebHostBuilderTests.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;
@@ -1129,6 +1129,33 @@ namespace Microsoft.AspNetCore.Hosting
Assert.Contains("No application configured.", exception.Message);
}
+ [Theory]
+ [MemberData(nameof(DefaultWebHostBuildersWithConfig))]
+ public void UseConfigurationWithSectionAddsSubKeys(IWebHostBuilder builder)
+ {
+ var config = new ConfigurationBuilder()
+ .AddInMemoryCollection(new[]
+ {
+ new KeyValuePair("key", "value"),
+ new KeyValuePair("nested:key", "nestedvalue"),
+ }).Build();
+ var section = config.GetSection("nested");
+
+ builder = builder
+ .CaptureStartupErrors(false)
+ .Configure(app => { })
+ .UseConfiguration(section)
+ .UseServer(new TestServer());
+
+ Assert.Equal("nestedvalue", builder.GetSetting("key"));
+
+ using (var host = builder.Build())
+ {
+ var appConfig = host.Services.GetRequiredService();
+ Assert.Equal("nestedvalue", appConfig["key"]);
+ }
+ }
+
private static void StaticConfigureMethod(IApplicationBuilder app) { }
private IWebHostBuilder CreateWebHostBuilder()