默認(rèn)的dotnet webapp啟動(dòng)的端口是5000和5001,有5種方式可以自定義
5 ways to set the URLs for an ASP.NET Core app (andrewlock.net)
用代碼
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
webBuilder.UseUrls("http://localhost:5003", "https://localhost:5004");
});
}
我喜歡參數(shù)的用法:
dotnet run --urls "http://localhost:5100;https://localhost:5101"
在linux下,可以直接在調(diào)用的可執(zhí)行文件后加這個(gè)參數(shù)也可以 ./dotnet6test.Server --urls "http://localhost:5100;https://localhost:5101" 也可以
還有環(huán)境變量:
You can set environment variables in the usual way based on your environment. For example, using the command line:
setx ASPNETCORE_URLS "http://localhost:5001"
using powershell
$Env: ASPNETCORE_URLS = "http://localhost:5001"
or using bash:
export ASPNETCORE_URLS="http://localhost:5001;https://localhost:5002"
官方文檔也可以參考一下這個(gè):Configure endpoints for the ASP.NET Core Kestrel web server | Microsoft Docs