Can I set listening URLs in appsettings.json in ASP.net Core 2.0 Preview?

I am creating an ASP.net Core 2.0 application to work in the .net Core 2.0 environment, as currently in their preview versions. However, I cannot figure out how to use Kestrel something different from the standard http://localhost:5000 URLs to listen to.

Most of the documentation that I can tell Google about setting up server.urls , which seems to have been changed even in the 1.0 preview to just be urls , but none of them work (when you turn on the logbook, Debug Kestrel tells me that no listening endpoints configured).

The documentation says a lot about hosting.json , and I cannot use defaultsetset.json by default. However, if I compare the recommended approach to loading a new configuration, it looks something like the new WebHost.CreateDefaultBuilder method WebHost.CreateDefaultBuilder , except that it loads appsettings.json.

Currently, I donโ€™t understand how the relationship between appsettings.json and IConfigureOptions<T> related, if at all possible, so my problem is due to a misunderstanding of what KestrelServerOptionsSetup really is.

+10
source share
5 answers

I worked 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 hosting .json

 { "urls": "http://*:5005;" } 
+16
source

Works for me as before

 WebHost.CreateDefaultBuilder(args) .UseConfiguration( new ConfigurationBuilder().AddCommandLine(args).Build() ) .UseStartup<Startup>() .Build(); 

Then

 dotnet myapp.dll --urls "http://*:5060;" 
+2
source

None of this helped me. This worked for me:

 public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>() .UseKestrel(options => { options.Listen(System.Net.IPAddress.Loopback, 44306, listenOptions => { listenOptions.UseHttps("mysertificate.pfx", "thecertificatePassword"); }); }) .Build(); 

(Change 44306 per port to your liking)

And in this fooobar.com/questions/848139 / ...

+1
source

To set the listening URL in appsettings.json, add the "Kestrel" section:

 "Kestrel": { "EndPoints": { "Http": { "Url": "http://localhost:5000" } } } 

Link: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-2.2

+1
source

John Sivertsen's answer Worked after publishing on Linux hosting. Thanks!

0
source

Source: https://habr.com/ru/post/1268111/


All Articles