Have you broken Kestrel configuration? #1442
Issue Title
Have you broken Kestrel configuration?
General
In .Net Core 1.0 in Main you used to be able to '.Build()' on the builder to get the configuration resolved, in order to be able to use configuration in .UseKestrel(...)
Unless I am mistaken, that is now not possible in 2.1 - one can only use constants or read from files by hand. Am I mistaken?
cheers
Matt
(upon advice, copied from here)
2.0 added lots of other ways to configure Kestrel, but the original ways mostly still worked. 2.1 has added even more ways...
There is one common confusion in 2.x where people try to use ConfigreAppConfiguration in Main to configure the Urls key, but you need to Configure the host instead.
Please show us how you are trying to configure it.
In Program.cs:
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.ConfigureAppConfiguration(ConfigConfiguration)
.ConfigureLogging(ConfigureLogger)
.Build();
Where ConfigConfiguration does a few config.AddJsonFile... I want to be able to do a .UseKestrel(...) and supply settings to kestrel read via the configuration system. In 2.0 you used to be able to do it like this.
The sample you linked to should work. Why are you using ConfigureAppConfiguration instead of UseConfiguration? It's the Urls parameter you're trying to set, correct?
Or you could try the new Endpoints config. https://github.com/aspnet/KestrelHttpServer/pull/2186
- Because I want to use multiple configuration files. Can't remember where I got the original pattern from, but you can also it being used here. And it is also the method used in the Sample startup.cs found when I follow your #2186 link
- No. I'm trying to set limits such as MaxRequestBufferSize
? MaxRequestBufferSize has never been mapped from config, in 1.x or 2.x. Or were you calling Bind?
No it has not been mapped from config. That is why we put it in our own config and set it in Main as per this example. That is why I want to be able to read our own config before the Kestrel initialisation and pass those settings in.
That is why I want to be able to read our own config before the Kestrel initialisation and pass those settings in.
Does the code from SO answer you linked to no longer work? 2.1 should be source compatible with 2.0 with few exceptions.
It does not work any more.
Previously .Build() returned an IConfigurationRoot
Now .Build() returns an IWebHost
In addition, you used to be able to call .Build() twice. Now if you do that you get an InvalidOperationException.
There are two builders in that example, a config builder and a web host builder. Make sure you're calling Build on the right one.
I'm putting this issue on hold until you post a complete code sample and error stack traces as relevant. None of the code samples or errors you've provided have been complete or matched the complaints you've made.
There are two builders in that example, a config builder and a web host builder That was the missing link. Did not realise. Apologies for wasting your time.