Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run asp.net core 2.1 release app at a specific port?

Tags:

asp.net-core

Environment: ASP.NET Core 2.1 under Ubuntu 18.04

By default, a newly created asp.net core app runs at http://localhost:5000 and automatically redirects to https://localhost:5001

As I intend to run my app under nginx (and use SSL capabilities of nginx), I would like to run my released app without https and at a specific port, say, 6000.

Post ASP.NET Core 2.1 + Kestrel (How to disable HTTPS) explains that one has to simply use "--urls" argument to achieve this.

Here is what I tried:

$ dotnet publish --configuration Release
$ dotnet bin/Release/netcoreapp2.1/MyApp.dll

The app now starts listening at http://localhost:5000 and https://localhost:5001. When I browse to http://localhost:5000, it automatically redirects to https://localhost:5001. So far so good.

Now, I try running at port 6000:

$ dotnet bin/Release/netcoreapp2.1/MyApp.dll
     --urls="http://localhost:6000"

From the messages in the terminal window, the app seems to start listening at http://localhost:6000. However, browsing to this url results in "this site can't be reached" error.

I even tried:

$ dotnet bin/Release/netcoreapp2.1/MyApp.dll
     --urls="http://localhost:6000,https://localhost:6001"

In this case, I get an error that "a path base can only be configured using IApplicationBuilder.UsePathBase()."

Can someone please tell me how I can simply run an application at a specified port? I am hoping I don't need to hard-code port numbers.

like image 875
Peter Avatar asked Nov 05 '18 07:11

Peter


2 Answers

"a path base can only be configured using IApplicationBuilder.UsePathBase()."

For this error, it is caused by you use , between urls. You need to use ; to split urls like below:

dotnet bin/release/netcoreapp2.1/publish/webapplication3.dll --urls="http://localhost:8000;https://localhost:8001"

I would like to run my released app without https and at a specific port, say, 6000.

For run without https, you need to remove the app.UseHttpsRedirection(); in Startup.cs

One More Note

If you fail to access 6000, I suggest you make a test with 8000, port 6000 is disabled by most browsers.

like image 140
Edward Avatar answered Sep 30 '22 15:09

Edward


According to this piece of documentation it should be something like dotnet run --urls "http://*:8080". So no equals sign in between. But according to the Kestrel documentation there are multiple ways to define a different port e.g. the ASPNETCORE_URLS environment variable.

like image 39
Kah Tang Avatar answered Sep 30 '22 15:09

Kah Tang