0

I have created a basic WebAPI with ASP.NET Core 6 and Visual Studio. I just get a main route that returns "Hello world", and modified port to use 8888 When I debug this, I can get my expected string if I use localhost:8888 however I'd like to make it work to when I run device:8888 (device been my machine's name). Seems I am using a Kestrel server. I've tried a few things, but were not working for me:

How do I get the kestrel web server to listen to non-localhost requests?

How to specify the port an ASP.NET Core application is hosted on?

https://learn.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel/endpoints?view=aspnetcore-7.0

Any ideas on how can I call http://device:8888 with my debug server running?

Sergioet
  • 1,108
  • 13
  • 27

2 Answers2

1

Firstly, I changed the launchsetting.json to change the applicationUrl as a custom name. Then I run the API project and get the error below. It indicates a DNS error. enter image description here

So I modify the host file to add 127.0.0.1 mycustomname and this time it worked for me.

enter image description here enter image description here

Tiny Wang
  • 10,423
  • 1
  • 11
  • 29
  • Is this what you want? – Tiny Wang Jan 27 '23 at 06:15
  • 1
    thank you @Tiny Wang - I don't think I need to modify my hosts to achieve that. I think I found the way of doing it - reading and understanding https://learn.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel/endpoints?view=aspnetcore-7.0 – Sergioet Jan 27 '23 at 10:33
  • 1
    thank you for your answer, Mr. Tiny Wang! :) – Sergioet Jan 27 '23 at 12:15
1

I used the following: Google Chrome redirecting localhost to https - to stop automatically converting localhost into https and then https://learn.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel/endpoints?view=aspnetcore-7.0 - a few ways of doing this:

  • using dot net run --urls=http://*:8888 (defines any device and port 8888)
  • using config, adding the following in appsettings.json
  "Kestrel": {
    "Endpoints": {
      "Http": {
        "Url": "http://localhost:5000"
      },
      "Https": {
        "Url": "https://localhost:5001"
      }
    }
  }

The doc also defines the use of ASPNETCORE_URLS but I was not able to make it work.

Sergioet
  • 1,108
  • 13
  • 27