KestrelHttpServer icon indicating copy to clipboard operation
KestrelHttpServer copied to clipboard

Have you broken Kestrel configuration? #1442

Open Mattacks opened this issue 8 years ago • 10 comments

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)

Mattacks avatar Apr 16 '18 10:04 Mattacks

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.

Tratcher avatar Apr 16 '18 11:04 Tratcher

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.

Mattacks avatar Apr 16 '18 13:04 Mattacks

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

Tratcher avatar Apr 16 '18 14:04 Tratcher

  1. 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
  2. No. I'm trying to set limits such as MaxRequestBufferSize

Mattacks avatar Apr 16 '18 15:04 Mattacks

? MaxRequestBufferSize has never been mapped from config, in 1.x or 2.x. Or were you calling Bind?

Tratcher avatar Apr 16 '18 15:04 Tratcher

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.

Mattacks avatar Apr 16 '18 16:04 Mattacks

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.

halter73 avatar Apr 16 '18 21:04 halter73

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.

Mattacks avatar Apr 17 '18 09:04 Mattacks

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.

Tratcher avatar Apr 17 '18 15:04 Tratcher

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.

Mattacks avatar Apr 17 '18 16:04 Mattacks