Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default Visual Studio project appsettings.json not allowing the configuration of server.urls #1915

Closed
jmessenger235 opened this issue Jan 28, 2017 · 7 comments

Comments

@jmessenger235
Copy link

Default Visual Studio project appsettings.json not allowing the configuration of server.urls

The functional impact of this is that applications that are hosted independently of IIS or tested in that context, require a separate additional configuration file must be added to the default web api project created in Visual Studio

In order to encounter this issue use visual studio 2015 and .net core 1.0.1 tools preview 2 and do the following:
Create a new ASP.NET core web application. (This can either target .net framework 4.6.1 or .net core as I tested both at one point but only verified these steps against the asp.net webapi project that targets the core)
Use the webapi sub-template.
Add: ","server.urls": "http://*:5005"" without the final open and closing double quotes before the final bracket of appsettings.json.
Start the application debugging in the non IIS option for starting and debugging.
Observer that the application binds to port 5000 rather than the specified port 5005

I would expect the default json configuration to allow the setting of server.urls and bind to port 5005.

In actuality, the server.urls parameter in the default appsettings.json is being ignored and the app is starting up listening on port 5000

The problem seems to be in WebHostBuilder.UseStartup. If I add a separate file hosting.json to the program.cs then it loads the parameter correctly and binds to the specified port. The reason I say this is that the same file specified via a configuration builder and added via WebHostBuilder.UseConfiguration properly loads the file and binds to the specified port 5005.

@Tratcher
Copy link
Member

For starters, "server.urls" is obsolete, it's just "urls" now.

Can you show your Program.Main code? You need to read config in Program.Main add assign it to WebHostBuilder if you want it to read hosting settings. The config in Startup is not applied to WebHostBuilder.

@jmessenger235
Copy link
Author

jmessenger235 commented Jan 30, 2017

The config in Startup is not applied to WebHostBuilder.

I am aware of this but I see it as a bug in one or more of documentation, template or framework. The fact you mention was not particularly clear to me from the documentation. Reading it with that understanding now, I see how it was intended that way, but is not at all the way I understood it because of the flow of examples, how they were referenced and the vague nature of how that fact was explained. Additionally, if that is how it is intended, I would think the default template should have a config that adds the environment variables and a hosting.json to the web builder. As is, I am left asking why there is an adding of environment variables to config in startup in the template if it doesn't apply to the web host builder. Even better IMO would be to apply the config in startup to the hosting settings. This is primarily for the reason that you have the environment there as part of the IHostingEnvironment. You don't have that in Program.Main without going through additional code to pull it out of an environment variable. The other reason is it would seem to reduce a lot of duplicate code in terms of needing to specify configurations in multiple places for hosting and for other settings.

The Program.Main is whatever the default web API template has. If memory serves it should be:

var host = new WebHostBuilder()
                .UseKestrel()
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseIISIntegration()
                .UseStartup<Startup>()
                .UseApplicationInsights()
                .Build();

host.Run();

@aspnet-hello
Copy link

This issue is being closed because it has not been updated in 3 months.

We apologize if this causes any inconvenience. We ask that if you are still encountering this issue, please log a new issue with updated information and we will investigate.

@davidalpert
Copy link

davidalpert commented Dec 30, 2017 via email

@davidalpert
Copy link

davidalpert commented Dec 30, 2017 via email

@szogun1987
Copy link

This issue still occurs. Application ignores both 'urls' and 'server.urls' parameters no matter if I pass them via command line or place in .json file. environment variable ASPNETCORE_URLS works fine.
I used publish --configuration Release --self-contained --runtime win-x64 to build mine solution. I have debug mine app a little bit and figured out that host._config file doesn't contains reference to most of configuration
image
But configuration is available later in app.

@szogun1987
Copy link

OK I figured out what was wrong. ConfigureAppConfiguration doesn't affect config used during app startup. It is used later.

ryanbrandenburg pushed a commit that referenced this issue Nov 26, 2018
@ghost ghost locked as resolved and limited conversation to collaborators Dec 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants