五、参数
一、配置json文件
1. 增加 host.json 文件,内容:
{ "urls": "http://localhost:5004;https://localhost:5005" }
2. 修改 Programe.cs
public static IWebHostBuilder CreateWebHostBuilder(string[] args) { var config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("host.json", optional: true) .Build(); var host = WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>() .UseConfiguration(config) ; return host; }
二、命令行方式
1. 修改 Program.cs
public static IWebHostBuilder CreateWebHostBuilder(string[] args) { var config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddCommandLine(args) //添加对命令参数的支持 .Build(); var host = WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>() ; return host; }
2. 运行 dotnet run 时加参数:
dotnet run --urls="http://*:5005"
点到为止