我正在使用 ASP.NET Core 6 天氣預報示例。在我的開發環境中,我可以運行該應用程式并將“默認”頁面顯示為localhost:xxxx/swagger/index.html.
在生產中,默認不顯示;如果我使用完整的 URL,我可以訪問它https://example.com/swagger
如何讓 ASP.NET Core 6(生產中)默認為該頁面?
我努力了:
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute("default", "{controller=swagger}");
});
它也不起作用。問題再次出在生產上。--launchUrl 僅在 dev 中有效(按設計)
uj5u.com熱心網友回復:
午餐設定.json
"ProductionEnvironment": {
//Some configuration...
//add this
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Production"
}
}
程式.cs
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
//add Production Environment
else if (app.Environment.IsProduction())
{
app.UseSwagger();
app.UseSwaggerUI();
}
當您添加上述配置時,該應用程式將顯示“默認”頁面,如localhost:xxxx/swagger/index.html在生產中。
uj5u.com熱心網友回復:
我使用以下代碼解決了這個問題:
app.UseRouting();
app.UseSwagger();
app.UseSwaggerUI();
app.UseEndpoints(endpoints =>
{
endpoints.MapGet("/", async context =>
{
context.Response.Redirect("swagger");
});
});
它現在按預期作業。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/404856.html
標籤:
上一篇:Mysql中如何設定定時任務
