Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 477
Henry Avatar asked May 22 '17 16:05

Henry


People also ask

What is the difference between Appsettings json and Appsettings development json?

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.

What is launch URL in launchSettings json?

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.

Should I commit Appsettings json?

the appsettings.Development. json should not be added to the git repository and that every developer should create his own appsettings.Development.

Can I add more than two Appsettings json files in dotnet core?

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.


1 Answers

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;" }
like image 95
Ígor Krug Avatar answered Oct 09 '22 12:10

Ígor Krug