You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET 8 Azure Functions部署后Swagger UI出现404错误求助

.NET 8 Azure Functions部署后Swagger UI 404问题排查与解决

项目依赖

我的.NET 8 Azure Functions应用包含以下依赖:

<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="MediatR" Version="12.4.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.20.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.2.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.OpenApi" Version="1.5.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.4" />
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.1.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />

问题现象

在VS2022本地运行时,可通过http://localhost:7230/api/swagger/ui正常访问Swagger UI;但部署到Azure后,应用已正常启动(能看到蓝色启动界面),访问同一路径却返回404错误。

排查过程

检查Application Insights日志,未发现对应的失败请求记录,排除了请求到达后处理出错的情况。

根因与解决

最终定位问题:Azure环境中未配置ASPNETCORE_ENVIRONMENT环境变量。添加该环境变量(通常设置为Development或根据需求设置对应环境值)后,Swagger UI即可正常访问。

内容的提问来源于stack exchange,提问作者Kirsten

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 22:02:15