How to modify the default port number of an asp.net core5 program
This article focuses on "how to change the default port number of asp.net core5 programs". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to change the default port number of asp.net core5 programs.
In the local development environment, we know that port switching can be achieved by changing the port number in the launchSettings.json file.
"WebApplication1": {"commandName": "Project", "launchBrowser": true, "launchUrl": "weatherforecast", "environmentVariables": {"ASPNETCORE_ENVIRONMENT": "Development"}, "applicationUrl": "https://*:8081;http://*:8080"}"
But after the release of the program, I found that it has been listening to port 5000, I would like to ask how I do port changes in the production environment, I tried UseUrls does not seem to work.
Public static IHostBuilder CreateHostBuilder (string [] args) = > Host.CreateDefaultBuilder (args) .ConfigureServices ((hostContext, services) = > {services.AddHostedService () }) .UseWindowsService () .ConfigureWebHostDefaults (webBuilder = > {webBuilder.UseStartup () .UseUrls ("http://*:8080","https://*:8081");})) .UseSerilog ()
It's okay to use UseUrls, but you reverse the order. Just swap webBuilder.UseStartup () with .UseUrls ("http://*:8080","https://*:8081")). I hope it works for you.
Public static IHostBuilder CreateHostBuilder (string [] args) = > Host.CreateDefaultBuilder (args) .ConfigureServices ((hostContext, services) = > {services.AddHostedService () }) .UseWindowsService () .ConfigureWebHostDefaults (webBuilder = > {webBuilder.UseUrls ("https://*:8081"," http://*:8080"); webBuilder.UseStartup ();}) .UseSerilog ();}
Stephen LAI:
You can configure it through the command line-- urls parameter when the program starts, as shown below:
Dotnet run-urls "http://localhost:5100;https://localhost:5101"
Or:
Dotnet / Product/Full/Path/Product.dll-- urls "http://localhost:5100;https://localhost:5101"
If we must manipulate the LaunchSettings.json file, it can also be achieved, just configure the iisSettings node.
{"iisSettings": {"iisExpress": {"applicationUrl": "http://localhost:8080"," sslPort ": 96085