var builder = WebApplication.CreateBuilder(args);
修改默认启动端口号,注意:http与https的端口号不能重复,(如果端口号重复情况下,不开启app.UseHttpsRedirection(),则走http,或者重复下其他的配置方法运行会报错),
只要开启app.UseHttpsRedirection()所有都会切换到https,与launchSettings.json配置无关。
1.UseUrls方法
builder.WebHost.UseUrls(new[] { "http://*:8090", "https://*:8091" });
builder.WebHost.UseUrls("https://*:8089");//单个设置
2.UseKestrel 方法
builder.WebHost.ConfigureKestrel(options => options.ListenLocalhost(8090, opts => opts.Protocols = HttpProtocols.Http1));
3. .NET 6 下新增方法
app.Urls.Add("http://localhost:8090");
app.Urls.Add("https://localhost:8091");
4.appsettings.json配置方法,建议使用
"Kestrel": {
"Endpoints": {
"Https": {
"Url": "https://*:9601"
},
"Http": {
"Url": "http://*:9600"
}
}
}



