0

I have two projects (.Net Core 3.1) in the same solution, the first one called "BackEnd" is a Web API and the second "FrontEnd" is a web application MVC.

My problem is the Web API Port because it changes everytime I restart my PC or use another Computer and I have to change the port in FrontEnd to keep consuming the API.

Is there a way to get the port of the Web API programmally?

2 Answers 2

2

Open launchSettings.jsonand specify the port in applicationUrl for configuration that you use

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:10042",
      "sslPort": 44353
    }
  },
  "$schema": "http://json.schemastore.org/launchsettings.json",
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "BackEnd": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "https://localhost:10040;http://localhost:10041"
    }
  }
}

or in Visual Studio, right-click on the project -> Properties, click on Debug and change the port number next to APP URL under the Web Server Settings

enter image description here

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

Comments

1

If both projects are in the same solution you can open "Properties" of the solution and in "Startup Project" tab select "Multiple Start Projects" and select both - "Back End" and "Front End" Projects. And an Api project "Properties", select "Debug" and if needed change the port number next to APP URL. That's it.

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.