什么是網(wǎng)站建設(shè)和維護(hù)廈門(mén)seo小謝
builder.WebHost.UseUrls 是 ASP.NET Core 中配置應(yīng)用程序監(jiān)聽(tīng) URL 或端口的方法。通過(guò)使用這個(gè)方法,你可以指定應(yīng)用程序應(yīng)該在哪些 URL 上運(yùn)行,以便接收 HTTP 請(qǐng)求。
1.在appsetting.json中 添加
"LaunchUrl": "http://*:327"
2.在Program中
string[]? urls = builder.Configuration.GetValue<string>("LaunchUrl")?.Split(",");builder.WebHost.UseUrls(urls ?? new string[0]);
//這是 C# 7 引入的空條件運(yùn)算符(null-conditional operator)。如果 GetValue<string>("LaunchUrl") 返回了 null,那么整個(gè)表達(dá)式將不會(huì)執(zhí)行,而是直接返回 null。//如果返回了有效的字符串,它將使用 Split 方法按逗號(hào)分割字符串,生成一個(gè)字符串?dāng)?shù)組(string[])。//例如,如果 LaunchUrl 的值為 "http://localhost:327,http://localhost:5000",那么 Split 方法將返回一個(gè)包含兩個(gè)元素的數(shù)組:["http://localhost:327", "http://localhost:5000"]。
if (app.Environment.IsDevelopment()){app.UseSwagger();app.UseSwaggerUI();}
改成
if (app.Environment.IsDevelopment()){}app.UseSwagger();app.UseSwaggerUI();
即可