I'm creating an ASP.net Core 2.0 app to run on the .net Core 2.0 runtime, both currently in their Preview versions. However, I cannot figure out how to have Kestrel use something other than the default http://localhost:5000
listen URL.
Most documentation that I could Google talks about a server.urls
setting, which seems to have been changed even in 1.0-preview to just be urls
, however neither works (turning on Debug logging has Kestrel telling me that no listen endpoints are configured).
A lot of documentation also talks about a hosting.json
and that I can't use the default appsettings.json. However, if I compare the recommended approach of loading a new config, this looks pretty much exactly like what the new WebHost.CreateDefaultBuilder
method does, except that it loads appsettings.json.
I currently don't understand how appsettings.json and IConfigureOptions<T>
are related, if at all, so it's possible that my trouble stems from a lack of understanding of what KestrelServerOptionsSetup
actually does.
NET Core and as far as I see from my search on the web, appsettings.Development. json is used for development config while developing the app and appsettings. Production. json is used on the published app in production server.
Using property applicationUrl in launchSettings. json file will be used to set start URL in ASP.NET Core applications. launchSettings.json file already contains the entries for default URLs i.e. http://localhost:5000 & https://localhost:5001 in project settings.
the appsettings.Development. json should not be added to the git repository and that every developer should create his own appsettings.Development.
Of course, we can add and use multiple appsettings. json files in ASP.NET Core project. To configure and read data from your custom json files, you can refer to the following code snippet. Host.
I got it working with this
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseConfiguration(new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("hosting.json", optional: true)
.Build()
)
.UseStartup<Startup>()
.Build();
And the hosting.json
{ "urls": "http://*:5005;" }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With