0

I have an ASP.NET Core project. I can't change port of this app.

launchSettings.json:

{
  "profiles": {
    "drip_chip_api": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development",
        "ASPNETCORE_URLS": "https://localhost:5000"
      },
      "dotnetRunMessages": true,
      "applicationUrl": "https://localhost:5000;http://localhost:5000"
    },
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "Docker": {
      "commandName": "Docker",
      "launchBrowser": true,
      "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
      "publishAllPorts": true,
      "useSSL": true
    }
  },
  "$schema": "https://json.schemastore.org/launchsettings.json",
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:20653",
      "sslPort": 5000
    }
  }
}

Despite these settings, it runs on https://localhost:49153.

How can I change the port?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Antonio
  • 299
  • 1
  • 4
  • 13
  • Does this answer your question? [How to change the port number for Asp.Net core app?](https://stackoverflow.com/questions/38755516/how-to-change-the-port-number-for-asp-net-core-app) – Aaron Feb 24 '23 at 07:37
  • 2
    `"Despite the settings it runs on https://localhost:49153"` Where does it runs? in local, IIS or docker? – Md Farid Uddin Kiron Feb 24 '23 at 07:45
  • I run it on docker – Antonio Feb 24 '23 at 11:21
  • 1
    `launchsetting.json` is [only used by IDEs during development](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-7.0#development-and-launchsettingsjson) to launch the application. Inside a container your application will start on port 80. You can forward this to any port you want through the docker file – Panagiotis Kanavos Feb 24 '23 at 11:58

1 Answers1

-1

If you click on the dropdown arrow here where you run the project:

Screenshot

You can see that you have different startup options. Select IIS Express or the one with your project name.

Then you can also go into Debug Properties (bottom of drop-down) and configure settings there.

I hope this helps.

EDIT: Since you mentioned you use Docker to run here is a helpful resource you can use to configure port: Docker Container Networking

This command switch should do the trick for you: Docker networking

8080 is port that you will access through, 80 is port inside the container (on this port your project listens). YOu can modify 8080 to your desired port, as long it is not used by any other service on your device.

This could also be helpful: Docker Container Debug in .NET Core

Martin Ferenec
  • 57
  • 1
  • 1
  • 9