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

API Trace View

Struggling with slow API calls?

Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs