Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine port in asp.net core

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?

like image 631
Thomas Geulen Avatar asked Dec 15 '16 13:12

Thomas Geulen


People also ask

How can I change port number in asp net core?

Change Port To change the port the application is using, Open the file lunchSetting. json. You will find it under the properties folder in your project and as shown below. Inside the file, change applicationUrl port (below is set to 5000) to a different port number and save the file.

What is port number in asp net?

We know that ASP.NET Core Application runs under Kestrel Server with default port number http://localhost:5000.

How do I change the port in net core 6?

Click on the Dropdown on the run button. Now click on debug properties. By clicking on that launch profile window will open. now you can change the port from the app URL from here.

How do I change the port number of a .NET application?

In Solution Explorer, click the name of the application. In the Properties pane, click the down-arrow beside Use dynamic ports and select False from the dropdown list. This will enable editing of the Port number property. In the Properties pane, click the text box beside Port number and type in a port number.


1 Answers

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

like image 82
Ody Avatar answered Sep 21 '22 15:09

Ody