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
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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();
}
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0