How can we change the default kestrel port when using new dotnet cli ? #639
Comments
I have found it!
|
Really thanks for making sure you posted what you found, this helped me! |
Note that this has been further changed in RC2: aspnet/Announcements#168 |
@joshcomley yes, thank you. I used this info to solve my problem with Docker port forwarding. The step that lead me here was https://blog.rendle.io/asp-net-5-dnx-beta8-connection-refused-in-docker/ And in my case I needed to specify all zeros in the IP: |
An alternative by passing arguments: |
You can also use the |
For the record, the pure single-line command-line usage to run aspnet-core app with custom port goes like this: dotnet new -t web
dotnet restore
# Unix:
ASPNETCORE_URLS="https://*:5123" dotnet run
# Windows PowerShell:
$env:ASPNETCORE_URLS="https://*:5123" ; dotnet run
# Windows CMD (note: no quotes):
SET ASPNETCORE_URLS=https://*:5123 && dotnet run IMO, there should be a default, simple, standard command-line usage like ROR web servers as well: http://guides.rubyonrails.org/command_line.html (extremely sane and logical command line options) dotnet run --environment Production --port 5123
dotnet run -e Production -p 5123
# just like:
bin/rails server --environment production --port 4000
bin/rails server -e production -p 4000 |
If anyone is interested I've built a dotnet cli extension that provides the functionality described by ghost above you can check it out here https://github.com/josh-bradley/DotNetRunWeb |
At least for Dotnet Core 1.1, This only works if you include
|
Thanks so much, |
So there is still no |
I don't think it makes much sense to specify the port without an IP. You could write something like this in Program.cs
|
Hello. |
It is possible to have 3 instances using different environment variables. A lot will depend on how you have Program.cs and Startup.cs configured. Dotnet Core by default assumes the environment is production. How to change the environment will partially depend on the OS. |
dotnetcore 1.1 public class Program
|
How can it be changed these days using ASP.NET Core 2.0 from the command line? |
if you use @ethanliew 's answer, there shouldnt be much you need to change to make Core 2.0 work. |
@TotzkePaul I was referring to a command line argument. |
See #1998 |
@TotzkePaul Ideally we wouldn't have to hard-code our IP/ports. This should be 100% configurable so we don't have to recompile the app if we decide to deploy the app to a different server having a different IP. |
I'll get an update on this in the next couple of days. I agree that the ports should be configurable via the command line. I think someone deleted their comment about "0.0.0.0 vs *". I think * is all handles (IPv4 and IPv6) while 0.0.0.0 is only IPv4 address. There is something else, let me know.
|
So I am using launchSettings.json to set pass in the variables. Each config should be separated by a space and have the format of "{Key}={Value}".
As far as I know, In the past, your StartUp constructor looked like
This is my project where I set it to use CommandLine to pass in args. |
install package
|
Solution provided by @bidianqing is still valid and works in Linux. |
good |
Is it possible to change/switch Kestrel port binding at runtime? |
Comments on closed issues are not tracked, please open a new issue with the details for your scenario. |
Hi,
When I run "dotnet run", kestrel starts serving at http://localhost:5000
How can I change it to http://localhost:5050 ?
I added a hosting.json file to project directory with the following content:
{
"server": "Microsoft.AspNetCore.Server.Kestrel",
"server.urls": "http://localhost:5050"
}
This is part of my project.json:
"content": [
"wwwroot",
"Views",
"hosting.json"
],
Any ideas ?
Thanks!
The text was updated successfully, but these errors were encountered: