How can I specify using dotnet cli to run my web app using specific configurations. I know hosting.json can be used but I did not find any documentation how to do this and how this relates to the dotnet cli.
Asked
Active
Viewed 1.8k times
6
-
Can you clarify what configurations you're trying to set? Are you trying to make it listen on a specific port or ip address? If so [this answer](http://stackoverflow.com/questions/37289816/how-to-start-a-asp-net-core-1-0-rc2-app-that-doesnt-listen-to-the-localhost/37289990#37289990) might be helpful – Daniel Grim May 21 '16 at 12:55
3 Answers
8
Look at this sample: https://github.com/aspnet/Security/blob/dev/samples/CookieSample/Program.cs#L11
Tweaked for command line:
public static void Main(string[] args)
{
var config = new ConfigurationBuilder().AddCommandLine(args).Build();
var host = new WebHostBuilder()
.UseKestrel()
.UseConfiguration(config)
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
Then call dotnet run server.urls=http://localhost:5001/

Tratcher
- 5,929
- 34
- 44
-
1
-
The orginal dotnet command is : dotnet run --urls "http://localhost:5100" dotnet run --urls "http://localhost:5100;https://localhost:5101" – XAMT May 02 '21 at 08:33
4
Try .UseUrls
on Program.cs with specific port.
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.UseUrls("http://localhost:5020")
.Build();
host.Run();
}
}

Hasan Tuna Oruç
- 1,656
- 15
- 16
-
I tried this and the output suggests that it's serving on the IP yet my phone still says it's not reachable for some reason. Although IIS on the same machine serves just fine!? – K-Dawg Mar 02 '20 at 23:08
0
try the below command, its sets the environment variable and you will be able to access with the IP:5000.
set ASPNETCORE_SERVER.URLS=http://0.0.0.0:5000/

Say
- 74
- 4