DEV Community

Cover image for How to Change Ports in .Net Applications
Abayomi Ogunnusi
Abayomi Ogunnusi

Posted on

How to Change Ports in .Net Applications

This is a straight forward article of how to change the port of a Dotnet application.

Different ways to change port in a Dotnet application

Using the CLI

dotnet run --urls "http://localhost:5001;https://localhost:5002"
Enter fullscreen mode Exit fullscreen mode

Using the launchSettings.json file

{
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "https://localhost:5002;http://localhost:5001"
    },
    "WebApplication1": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "https://localhost:5002;http://localhost:5001"
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Using the appsettings.json file

{
  "Kestrel": {
    "Endpoints": {
      "Http": {
        "Url": "http://localhost:5001"
      },
      "HttpsInlineCertFile": {
        "Url": "https://localhost:5002",
        "Certificate": {
          "Path": "localhost.pfx",
          "Password": "password"
        }
      }
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Using app.Run()


app.Run("http://localhost:5001");
app.Run("https://localhost:5002");
Enter fullscreen mode Exit fullscreen mode

Using the UseUrls() method

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
        .UseUrls("http://localhost:5001", "https://localhost:5002")
        .UseStartup<Startup>();
Enter fullscreen mode Exit fullscreen mode

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Heroku

This site is powered by Heroku

Heroku was created by developers, for developers. Get started today and find out why Heroku has been the platform of choice for brands like DEV for over a decade.

Sign Up

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay