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" 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" } } } Using the appsettings.json file
{ "Kestrel": { "Endpoints": { "Http": { "Url": "http://localhost:5001" }, "HttpsInlineCertFile": { "Url": "https://localhost:5002", "Certificate": { "Path": "localhost.pfx", "Password": "password" } } } } } Using app.Run()
app.Run("http://localhost:5001"); app.Run("https://localhost:5002"); Using the UseUrls() method
public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseUrls("http://localhost:5001", "https://localhost:5002") .UseStartup<Startup>();
Top comments (0)