-
Notifications
You must be signed in to change notification settings - Fork 308
Urls not read from appsettings.json #1299
Comments
I guess this may've already been discussed at some length* but it continues to burn new users (e.g., me)... The issue is that you don't appear to be able to configure the webhost port via a config file or command line out of the box when you create a project via: $ dotnet new razor The WebHostBuilder already parses appsettings.json and the command line args and hydrates the Startup object IConfigure so my patch attempt seemed like an easy way to reduce astonishment. * https://stackoverflow.com/a/45854704/93345 |
[Rambling investigation] The command line issue was fixed here: aspnet/MetaPackages#221. The workaround is here: aspnet/MetaPackages#221 (comment) A similar workaround works for appsettings.json as well. The new Kestrel config file support also reads from appsettings.json. So the remaining gap is reading Urls from appsettings.json. Right now it's read from the wrong config layer. Hosting builds an initial configuration and services so it has enough information to build the rest of the app, like the Environment. But it also reads Urls from this config.
The other config is built seperately and added to the app services: Hosting/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs Lines 246 to 256 in cd3f58b
Option A to fix this would be to resolve the IConfiguration from the app services like how it resolves the server except as optional.
That config could be used as another entry in the fallback search, likely after the existing items to minimize the compat risk.
Or option B we change WebHostBuilder to pass in the app's config into WebHost from
Hosting/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs Lines 186 to 190 in cd3f58b
Recommendation: Option A |
We'll reconsider this in 2.2 cc @glennc |
Recommendation is to set the URLs with server specific settings. We won't be making other changes here. |
Did this " Urls not read from appsettings.json or command line to Urls not read from appsettings.json" sorted ?? I am trying to make this work with no luck . Just wondering if you can help me please , thank you |
No, we opted not to take this change. 2.1 offers a different way to configure urls for kestrel from the config file. See the new kestrel docs. https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-2.1&tabs=aspnetcore2x#how-to-use-kestrel-in-aspnet-core-apps |
The command line urls parameter did get fixed for 2.1. |
It seems that the impact should be small because the host's config in used as the first config provider when creating the app's config. Why would option B be so risky? |
The host's config and app's config are constructed differently, and _context.Configuration is completely replaceable so it may not be based on the host's config. Changing this risks regressing apps that are working today. You can already achieve the same functionality using Kestrel's new config section. |
I wasted a lot of time on this, assuming that The following
|
See #1298 for my quick attempt at a fix via the GitHub web interface.
The text was updated successfully, but these errors were encountered: