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

Azure App Service部署EF Core7时Managed Identity认证失败(400错误)

问题:Azure部署后ManagedIdentityCredential认证失败,本地正常

问题详情

在VS Code本地开发环境中,连接字符串可正常连接Azure SQL数据库,但部署到Azure环境后出现错误:ManagedIdentityCredential authentication failed: Service request failed。改用普通用户名密码的连接字符串时,Azure环境可正常运行。

使用的连接字符串

Server=tcp:asi-sql-dev.database.windows.net,1433;Initial Catalog=anabelle;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;Authentication='Active Directory Default'

EF Core配置代码

var connectionString = string.Empty;
if (builder.Environment.IsDevelopment())
{
    connectionString = builder.Configuration.GetConnectionString("AzureSQL");
}
else
{
    connectionString = Environment.GetEnvironmentVariable("AzureSQL");
}

builder.Services.AddDbContext<DataContext>(options =>
{
    options.UseSqlServer(connectionString);
});

请问遗漏了什么配置?

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 00:52:33