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

添加Microsoft.Identity.Web后ASP.NET Core7 WebAPI的Azure Web App启动失败

问题:ASP.NET Core 7 WebAPI添加Microsoft.Identity.Web后Azure Web App无法启动

在ASP.NET Core 7 WebAPI项目中添加Microsoft.Identity.Web引用(同时使用NSwag)后,部署到Azure Web App无法启动。

配置代码(Program.cs)

using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Identity.Web;

services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
        .AddMicrosoftIdentityWebApi(options =>
        {
            builder.Configuration.Bind("AzureAdB2C", options);

            options.TokenValidationParameters.NameClaimType = "emails";
        },
   options => { builder.Configuration.Bind("AzureAdB2C", options); });

启动异常日志

2023-10-12T16:07:25.283502021Z Documentation: http://aka.ms/webapp-linux
2023-10-12T16:07:25.283505121Z Dotnet quickstart: https://aka.ms/dotnet-qs
2023-10-12T16:07:25.283508021Z ASP .NETCore Version: 7.0.12
2023-10-12T16:07:25.283511021Z Note: Any data outside '/home' is not persisted
2023-10-12T16:07:26.566706113Z Starting OpenBSD Secure Shell server: sshd.
2023-10-12T16:07:27.025878864Z Starting periodic command scheduler: cron.
2023-10-12T16:07:27.036415801Z Running oryx create-script -appPath /home/site/wwwroot -output /opt/startup/startup.sh -defaultAppFilePath /defaulthome/hostingstart/hostingstart.dll     -bindPort 8080 -bindPort2 '' -userStartupCommand 'dotnet Pyxis.dll' 
2023-10-12T16:07:27.513081949Z Could not find build manifest file at '/home/site/wwwroot/oryx-manifest.toml'
2023-10-12T16:07:27.513133748Z Could not find operation ID in manifest. Generating an operation id...
2023-10-12T16:07:27.520703403Z Build Operation ID: 66a6a46e-827a-437d-a4a1-9573ed15fdc6
2023-10-12T16:07:28.246319362Z 
2023-10-12T16:07:28.246362562Z Agent extension disabled
2023-10-12T16:07:28.263715058Z Before if loop >> DotNet Runtime 
2023-10-12T16:07:28.366757042Z DotNet Runtime 7.0Writing output script to '/opt/startup/startup.sh'
2023-10-12T16:07:28.582742850Z Running user provided startup command...
2023-10-12T16:07:41.814918942Z Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.IdentityModel.Logging, Version=6.33.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
2023-10-12T16:07:41.814977242Z 
2023-10-12T16:07:41.814985742Z File name: 'Microsoft.IdentityModel.Logging, Version=6.33.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
2023-10-12T16:07:41.814990342Z    at Microsoft.Identity.Web.MicrosoftIdentityBaseAuthenticationBuilder..ctor(IServiceCollection services, IConfigurationSection configurationSection)
2023-10-12T16:07:41.814994942Z    at Microsoft.Identity.Web.MicrosoftIdentityWebApiAuthenticationBuilder..ctor(IServiceCollection services, String jwtBearerAuthenticationScheme, Action`1 configureJwtBearerOptions, Action`1 configureMicrosoftIdentityOptions, IConfigurationSection configurationSection)
2023-10-12T16:07:41.814999542Z    at Microsoft.Identity.Web.MicrosoftIdentityWebApiAuthenticationBuilderExtensions.AddMicrosoftIdentityWebApi(AuthenticationBuilder builder, Action`1 configureJwtBearerOptions, Action`1 configureMicrosoftIdentityOptions, String jwtBearerScheme, Boolean subscribeToJwtBearerMiddlewareDiagnosticsEvents)
2023-10-12T16:07:41.822980694Z    at Program.<Main>$(String[] args) in /opt/atlassian/pipelines/agent/build/Pyxis2/Program.cs:line 26
2023-10-12T16:07:47.185548054Z /opt/startup/startup.sh: line 18:    74 Aborted                 (core dumped) dotnet Pyxis.dll

解决思路

  • 检查依赖完整性:确认Microsoft.IdentityModel.Logging等Microsoft.Identity.Web的依赖包是否被正确包含在发布包中。查看项目.csproj文件,确保所有必要NuGet包已引用,且默认的CopyLocal配置未被修改。
  • 清理重发布:本地执行dotnet clean清除旧构建文件,再执行dotnet publish -c Release重新生成完整发布包,避免缓存依赖缺失问题。
  • 验证部署流程:如果使用自动化部署(如CI/CD流水线),检查构建步骤是否正确还原所有NuGet包,且发布的是完整输出目录,无文件遗漏。
  • 版本兼容性检查:确认Microsoft.Identity.Web版本与ASP.NET Core 7兼容,尝试升级或降级到稳定兼容版本,排除版本冲突导致的依赖缺失。
  • 检查发布目录内容:通过Azure门户的Kudu工具查看Web App的wwwroot目录,确认Microsoft.IdentityModel.Logging.dll是否存在,若缺失可手动复制对应dll到发布目录后重新部署测试。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.08 19:04:54