Change Default Port Number of ASP.NET App

Server Endpoints

There is a file in root folder called appsettings.json with you can change the server related configuration, this is an example with Kestrel:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://localhost:5400"
},
"Https": {
"Url": "https://localhost:5401"
}
}
}
}
{ "Logging": { "LogLevel": { "Default": "Information", "Microsoft.AspNetCore": "Warning" } }, "AllowedHosts": "*", "Kestrel": { "Endpoints": { "Http": { "Url": "http://localhost:5400" }, "Https": { "Url": "https://localhost:5401" } } } }
{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "Kestrel": {
    "Endpoints": {
      "Http": {
        "Url": "http://localhost:5400"
      },
      "Https": {
        "Url": "https://localhost:5401"
      }
    }
  }
}

From command line

You can run the application with the --urls parameter to specify the ports:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
dotnet run --urls http://localhost:8076
dotnet run --urls http://localhost:8076
dotnet run --urls http://localhost:8076

References
https://stackoverflow.com/questions/70332897/how-to-change-default-port-no-of-my-net-core-6-api