How to start a ASP.NET Core 1.0 RC2 app that doesn't listen to the localhost
Asked Answered
C

1

3

how can I start the ASP.NET Core with the dotnet CLI samples so that they don't listen to the localhost?

This command doesn't work:

dotnet run --server.urls=http://*:5000
Colter answered 18/5, 2016 at 3:33 Comment(1)
What do you mean by "doesn't work" ?Pert
B
6

What you're trying to do requires you to add command-line args to your configuration in the Main method of your application. Add something like this before you create your WebHostBuilder object:

var config = new ConfigurationBuilder()
    .AddCommandLine(args)
    .Build();

And then add this to the WebHostBuilder object before calling .Build() on it:

.UseConfiguration(config)

You'll also need to add a dependency to project.json:

"Microsoft.Extensions.Configuration.CommandLine": "1.0.0-rc2-final",

And finally, add a using statement to the file that your Main method is in:

using Microsoft.Extensions.Configuration;

Example Main method:

public static void Main(string[] args)
{
    var config = new ConfigurationBuilder()
        .AddCommandLine(args)
        .Build();

    var host = new WebHostBuilder()
        .UseKestrel()
        .UseConfiguration(config)
        .UseStartup<Startup>()
        .Build();
    host.Run();
}
Benedetto answered 18/5, 2016 at 3:53 Comment(1)
You can also configure urls directly in code, like in this samle: .UseKestrel().UseUrls("http://*:5000")Christan

© 2022 - 2024 — McMap. All rights reserved.