From what I understand the correct way of setting listen ports for ASP Dotnet Core 2 preview 1/2 is by creating a Kestrel section in the appsettings.json in the following format:
"Kestrel": {
"EndPoints": { //Could also be Endpoints, it's a bit unclear
"Http": {
"Address": "127.0.0.1",
"Port": 9001 //the port you want Kestrel to run on
},
I have tried to set up the sample webapp on a Debian machine, but when I start the app, it writes out that the app is listing on port 5000, the default port..
I know that the appsettings.json is read, because when I change the logging level to Trace, I get more info upon startup, including that no Endpoints are found and the app will use the standard 5000 port.
I have tried to search the aspnet source code on Github, and I can find a area where the Kestrel section is read from configuration (https://github.com/aspnet/Identity/blob/e38759b8a2de1b7a4a1c19462e40214b43c1cf3b/samples/IdentityOIDCWebApplicationSample/MetaPackage/KestrelServerOptionsSetup.cs), but as you can see it looks like a sample project.
What am I missing, isn't this the standard way to configure Kestrel in ASP Dotnet core 2?
I am use Program.cs and hosting.json file to config Kestrel. Example:
hosting.json:
This is exapmle for the latest version dotnet core. For earlier versions: hosting.json:
I know that this is an old post but to run visual studio with kestrel.
just edit the appsettings.json and add the config like this (tested with NetCore 2.0 and 2.1)
As mentioned in a comment on the accepted answer, 2.1 has support for appsettings.json, see https://blogs.msdn.microsoft.com/webdev/2018/02/02/asp-net-core-2-1-roadmap/#security
A working appsettings.json:
This is for a Program.cs using (created by "dotnet new webapi"):
Relevant source code in github https://github.com/aspnet/MetaPackages/blob/master/src/Microsoft.AspNetCore/WebHost.cs#L163
and https://github.com/aspnet/MetaPackages/blob/master/src/Microsoft.AspNetCore/WebHost.cs#L169
Support for Kestrel configuration via appsettings.json has been dropped in 2.0.
See this issue comment:
To get around this, you can do something like this in program.cs:
I had the same issue whereby my Kestrel configuration in appsettings.json is not being picked up. From this article about migrating from asp.net core 2.0 to 2.1, I updated the bootstraping code to become like the below, and it worked for me.