# HTTP 错误 502.5 - ANCM 进程外启动失败

- **ID:** `cloud/azure-app-service-http-502-bad-gateway`
- **领域:** cloud
- **类别:** runtime_error
- **错误码:** `502.5`
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

托管在 Azure 应用服务上的 ASP.NET Core 应用程序因缺少运行时依赖项、启动命令不正确或应用程序与 IIS ANCM 模块之间的端口不匹配而无法启动。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Azure App Service Windows | active | — | — |
| .NET 6 | active | — | — |
| .NET 8 | active | — | — |
| ASP.NET Core Module 18.0 | active | — | — |

## 解决方案

1. ```
   Enable detailed error logging via `appsettings.json`: set `"ASPNETCORE_DETAILEDERRORS": "true"` and `"ASPNETCORE_ENVIRONMENT": "Development"` in the App Settings blade; then redeploy and check the stdout log at `D:\home\LogFiles\stdout\`. Fix any missing NuGet packages or framework versions.
   ```
2. ```
   Ensure the application listens on the correct port by adding `UseUrls` in `Program.cs` or setting the `PORT` environment variable to `8080` (the default port ANCM expects). Example: `webBuilder.UseUrls("http://*:8080");` in `CreateHostBuilder`.
   ```

## 无效尝试

- **** — The application binary or its dependencies are still broken; restarting only re-executes the same failing startup sequence. (90% 失败率)
- **** — The stdout log may show generic messages; the actual error (e.g., 'Could not load file or assembly') is often written to stderr or the Windows Event Log. (65% 失败率)
