2

My ASP.NET Core 2.1 webapp works perfectly on my dev setup. Now I want to test it in production.

The production server is Ubuntu 18. I followed the instructions. I don't want to setup nginx yet, just do some quick tests, and the instructions say:

"Either configuration—with or without a reverse proxy server—is a valid and supported hosting configuration for ASP.NET Core 2.0 or later apps".

So I built and published my project: dotnet publish --configuration Release. Then on the server:

  • install the dotnet runtime
  • copied files to server (/var/www/myapp)
  • opened ports: sudo uwf allow 5000/tcp 80/tcp
  • run dotnet MyApp.dll (also tried sudo dotnet MyApp.dll)

It runs without errors/warnings, and says it's listening on http://localhost:5000.

On my local machine I tried http://serveripaddress (and http://serveripaddress:5000) but get nothing ("can't connect"). I can access that server with ssh, sftp, etc - only http isn't working.

What am I doing wrong?

2 Answers 2

6

the host default bind is 127.0.0.1 , so you can only access the app locally. if you want to access it from Network, please add --urls parameter. for example :

for development, you can run:

dotnet run --urls http://0.0.0.0:5000

and for deployed project, you can run:

dotnet MyApp.dll --urls http://0.0.0.0:5000

The dotnet core sdk I use is version 2.1.400.

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

5 Comments

That doesn't work on 2.1 - I think they removed that option. See my answer.
may be they adjust the parameter name, I will try it , there should be a parameter can change the binding address.
My way works, but I prefer your way - I hope there is a new parameter for this.
@lonix , I have tried, it works, please see my edited answer.
Doesn't work for me. I ran dotnet --info which shows host is version 2.1.3. I remember reading somewhere that urls is no longer supported. I'm not sure why it works for you but not me. Thanks anyway.
4

Found the problem. I needed to use:

ASPNETCORE_URLS="http://0.0.0.0:5000" sudo dotnet MyApp.dll

Then it logs Now listening on: http://0.0.0.0:5000. And I can access that from a remote client.

2 Comments

where exactly are you entering this "command"? are you sure sudo is correct?
Sorry but I don't remember - that was a long time ago, and the sdk has been upgraded since then. However I'm sure it's a typo and the sudo should come after the environment variable.

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.