6

I want to make some microservices with asp.net core (Web Api) For service discovery I want use Consul where I must register the services via the HTTP API including IP and port.

My question is: How can I know which port is used within in a service? Is there a way to determine the used port via code?

ekad
  • 14,436
  • 26
  • 44
  • 46
Thomas Geulen
  • 201
  • 5
  • 14

1 Answers1

7

Yeah, Use HttpContext.Connection.LocalPort to get the local port that the server is listening on.

Ody
  • 2,012
  • 4
  • 25
  • 35