![](/img/trans.png)
[英]Can't deploy ASP.NET react Web App with individual accounts — fail: Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler[3]
[英]Microsoft.AspNetCore.Authentication.JwtBearer Error when deploying Asp.Net Core with React.js template (dotnet SDK v7.0.101) to Azure Web App
我嘗試將帶有 React.js 模板 (do.net SDK v7.0.101) 的 Asp.Net Core 部署到具有“個人帳戶”身份驗證類型的新 Azure Web 應用程序。
應用程序在使用 localhost 時正常運行,但在部署后無法正常運行。 我收到以下錯誤:
[Error]
Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler:
Exception occurred while processing message.System.NullReferenceException:
Object reference not set to an instance of an object.at
Microsoft.AspNetCore.ApiAuthorization.IdentityServer.
IdentityServerJwtBearerOptionsConfiguration.ResolveAuthorityAndKeysAsync(MessageReceivedContext messageReceivedContext)
at Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync()
我懷疑它是 appsettings.json 中 IdentityServer 設置的問題:
"IdentityServer": {
"Clients": {
"AspNetCoreWithReactjs": {
"Profile": "IdentityServerSPA"
}
}
},
當我使用appsettings.Development.json IdentityServer 設置進行部署時,頁面加載但登錄不起作用。
我希望了解 Asp.Net IdentiyServer 的人可以建議我在 appsettings.json、program.cs 或其他地方需要做什么來解決這個錯誤。
除了連接字符串之外,提供的模板中沒有任何更改,所以我不確定為什么它沒有成功部署。
預期結果:
我期待頁面加載和工作的方式與通過本地主機運行時相同。
重現步驟:
新項目
配置您的新項目:
附加信息:
Appsettings.json 連接字符串
發布個人資料
發布:
發布后,url 加載出現 500 服務器錯誤:
來自 Azure 日志的詳細信息:
Connecting...
2023-01-01T12:58:30 Welcome, you are now connected to log-streaming service. The default timeout is 2 hours. Change the timeout with the App Setting SCM_LOGSTREAM_TIMEOUT (in seconds).
2023-01-01 12:58:36.131 +00:00 [Error] Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler: Exception occurred while processing message.System.NullReferenceException: Object reference not set to an instance of an object.at Microsoft.AspNetCore.ApiAuthorization.IdentityServer.IdentityServerJwtBearerOptionsConfiguration.ResolveAuthorityAndKeysAsync(MessageReceivedContext messageReceivedContext)at Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync()
2023-01-01 12:58:36.150 +00:00 [Error] Microsoft.AspNetCore.Server.IIS.Core.IISHttpServer: Connection ID "17582052946865029492", Request ID "80000176-0000-f400-b63f-84710c7967bb": An unhandled exception was thrown by the application.System.NullReferenceException: Object reference not set to an instance of an object.at Microsoft.AspNetCore.ApiAuthorization.IdentityServer.IdentityServerJwtBearerOptionsConfiguration.ResolveAuthorityAndKeysAsync(MessageReceivedContext messageReceivedContext)at Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync()at Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync()at Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.AuthenticateAsync()at Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext context, String scheme)at Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.AuthenticateAsync()at Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext context, String scheme)at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT`1.ProcessRequestAsync()
#Software: Microsoft Internet Information Services 8.0
#Fields: date time s-sitename cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) cs(Cookie) cs(Referer) cs-host sc-status sc-substatus sc-win32-status sc-bytes cs-bytes time-taken
2023-01-01 12:57:59 ASPNETCOREWITHREACTJS20230101233926 GET / X-ARR-LOG-ID=392d3d5f-4c6c-47ff-b6a1-c99b689a7fb2 443 - 120.148.130.43 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/108.0.0.0+Safari/537.36+Edg/108.0.1462.54 ARRAffinity=146b48f2ff5efabcc69048783c5815d34c57b6d7adedb21b164d0e292cee67ef;+ARRAffinitySameSite=146b48f2ff5efabcc69048783c5815d34c57b6d7adedb21b164d0e292cee67ef https://portal.azure.com/ aspnetcorewithreactjs20230101233926.azurewebsites.net 500 0 0 366 1700 5379
2023-01-01 12:57:59 ~1ASPNETCOREWITHREACTJS20230101233926 GET /api/logstream/ X-ARR-LOG-ID=058aae75-bbeb-442b-adf5-7585174fab8b 443 - 120.148.130.43 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/108.0.0.0+Safari/537.36+Edg/108.0.1462.54 - - aspnetcorewithreactjs20230101233926.scm.azurewebsites.net 200 0 64 672 1603 35233
截圖:
您是否閱讀過 Microsoft在 Azure App Service with a custom domain and certificate 中針對IdentityServer
Host 的帖子? 鑒於IdentityServerJwtBearerOptionsConfiguration.ResolveAuthorityAndKeysAsync
失敗,我認為這與此有關。
為Blazor WebAssembly
編寫,但身份服務器區域仍然相同。
我也在這里寫了一個如何解決的答案:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.