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

风格不统一 提交于 2019-11-30 06:59:38

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;" }

To set listen URLs in appsettings.json, add "Kestrel" section:

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

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

Works for me as it used to be

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

Then

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

None of the above worked for me. This one 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 the 44306 to a port of your own liking)

And there might be a lot of help in this StackOverflow answer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!