6

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.

2 Answers 2

10

"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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your help. I should have tested a different port than 6000:-(
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.