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

Azure Web App部署ASP.NET Core+React模板项目异常求助

ASP.NET Core + React Azure Web App启动超时故障

问题背景

  • 运行数月的Azure Web App突然故障,重新部署后无法恢复正常
  • 新建Azure Web App,部署Visual Studio 2022默认生成的ASP.NET Core with React.js模板项目,依旧出现异常
  • 当前使用B1服务计划,已尝试.NET 6.0和.NET 7.0版本

项目配置与代码

appsettings.json

{
  "ConnectionStrings": {
    "DefaultConnection": "*****************************************"
  },
  "Logging": {
      "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
      }
    },
  "IdentityServer": {
    "Clients": {
      "Project4": {
        "Profile": "IdentityServerSPA"
      }
    }
  },
"AllowedHosts": "*"
}

Program.cs

using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.UI;
using Microsoft.EntityFrameworkCore;
using Project4.Data;
using Project4.Models;

var builder = WebApplication.CreateBuilder(args);

// 注册服务
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection") ?? throw new InvalidOperationException("未找到连接字符串'DefaultConnection'。");
builder.Services.AddDbContext<ApplicationDbContext>(options =>
    options.UseSqlServer(connectionString));
builder.Services.AddDatabaseDeveloperPageExceptionFilter();

builder.Services.AddDefaultIdentity<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = true)
    .AddEntityFrameworkStores<ApplicationDbContext>();

builder.Services.AddIdentityServer()
    .AddApiAuthorization<ApplicationUser, ApplicationDbContext>();

builder.Services.AddAuthentication()
    .AddIdentityServerJwt();

builder.Services.AddControllersWithViews();
builder.Services.AddRazorPages();

var app = builder.Build();

// 配置HTTP请求管道
if (app.Environment.IsDevelopment())
{
    app.UseMigrationsEndPoint();
}
else
{
    // 默认HSTS值为30天,生产环境可根据需要调整
    app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();

app.UseAuthentication();
app.UseIdentityServer();
app.UseAuthorization();

app.MapControllerRoute(
    name: "default",
    pattern: "{controller}/{action=Index}/{id?}");
app.MapRazorPages();

app.MapFallbackToFile("index.html");

app.Run();

错误信息

在部署工具>控制台执行dotnet Project4.dll时收到以下提示:

命令'starter.cmd dotnet Project4 ...'因60秒内无输出且无CPU活动被终止。如有需要,可增加SCM_COMMAND_IDLE_TIMEOUT应用设置(如果是WebJob则增加WEBJOBS_IDLE_TIMEOUT)

排查与解决方法

  • 检查数据库连接:确认DefaultConnection指向的数据库服务器允许Azure Web App的出站IP访问,验证用户名、密码、数据库名称正确性,本地测试连接是否正常
  • 调整SCM超时:在Azure门户的Web App配置>应用程序设置中,添加或更新SCM_COMMAND_IDLE_TIMEOUT为180秒,延长启动等待时间
  • 查看详细日志:启用Web App的详细错误日志和Web服务器日志,重启后查看日志流,定位具体启动异常
  • 完成数据库迁移:本地执行dotnet ef database update完成迁移后再部署,或在Azure控制台直接执行迁移命令
  • 临时升级服务计划:将B1升级到B2或更高版本,测试是否因资源不足导致启动超时

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 05:07:49