5

I was struggling to use custom urls for Kestrel and I finally found a combination of settings and builders that work but I'm really confused why does the following work:

var configuration =
    new ConfigurationBuilder()
        .AddJsonFile("hosting.json", optional: true, reloadOnChange: true)
        .Build();

var host =
    WebHost.CreateDefaultBuilder(args)
        .UseContentRoot(contentRootPath)
        .UseConfiguration(configuration)
        .UseStartup<Startup>()
        .Build();

but not this:

var host =
    WebHost.CreateDefaultBuilder(args)
        .UseContentRoot(contentRootPath)
        .ConfigureAppConfiguration((context, builder) => 
        { 
            builder.AddJsonFile("hosting.json", optional: true, reloadOnChange: true); 
        })
        .UseStartup<Startup>()
        .Build();

It just ignores the hosting.json file as if it wasn't there.


What is the difference between using your own builder vs. using the ConfigureAppConfiguration extension? Is there a rule of thumb when to use which?

t3chb0t
  • 16,340
  • 13
  • 78
  • 118
  • 4
    This is by design, though this design does not make any sense to me: https://github.com/aspnet/Hosting/issues/1148 – Evk Mar 05 '18 at 11:11
  • 1
    @Evk holy cow, thanks. I guess I asked google the wrong keywords and didn't find this git-issue... – t3chb0t Mar 05 '18 at 11:14
  • 2
    It's and order of operations issue. UseConfiguration configures the host and server, where ConfigureAppConfiguration configures only the app. – Tratcher Mar 05 '18 at 16:39

0 Answers0