Microsoft ASP.NET Core Identity 框架在“发布”配置上崩溃?

问题描述 投票:0回答:1

我正在构建一个与 ASP.NET Core Web API(与 SQL 数据库通信)通信的 Blazor WASM 前端。我已经完成了所有设置,并且在我的机器上的“调试”配置中运行良好。然后,我使用前端的静态 Web 应用程序和后端的 Web 应用程序将两者部署到 Azure。

然后我必须意识到,如果我尝试注册新用户,应用程序会在浏览器控制台中抛出此错误代码(既发生在部署版本中,也发生在我在发布配置中本地运行应用程序时) :

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: ExpectedJsonTokens Path: $ | LineNumber: 0 | BytePositionInLine: 0.
System.Text.Json.JsonException: ExpectedJsonTokens Path: $ | LineNumber: 0 | BytePositionInLine: 0.
 ---> System.Text.Json.JsonReaderException: ExpectedJsonTokens LineNumber: 0 | BytePositionInLine: 0.
   at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& , ExceptionResource , Byte , ReadOnlySpan`1 )
   at System.Text.Json.Utf8JsonReader.Read()
   at System.Text.Json.Serialization.JsonConverter`1[[ASBNApp.Frontend.Model.Identity.RegisterAccountBadRequest, ASBNApp.Frontend, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].ReadCore(Utf8JsonReader& , JsonSerializerOptions , ReadStack& )
   Exception_EndOfInnerExceptionStack
   at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& , JsonReaderException )
   at System.Text.Json.Serialization.JsonConverter`1[[ASBNApp.Frontend.Model.Identity.RegisterAccountBadRequest, ASBNApp.Frontend, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].ReadCore(Utf8JsonReader& , JsonSerializerOptions , ReadStack& )
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1[[ASBNApp.Frontend.Model.Identity.RegisterAccountBadRequest, ASBNApp.Frontend, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].Deserialize(Utf8JsonReader& , ReadStack& )
   at System.Text.Json.JsonSerializer.ReadFromSpan[RegisterAccountBadRequest](ReadOnlySpan`1 , JsonTypeInfo`1 , Nullable`1 )
   at System.Text.Json.JsonSerializer.ReadFromSpan[RegisterAccountBadRequest](ReadOnlySpan`1 , JsonTypeInfo`1 )
   at System.Text.Json.JsonSerializer.Deserialize[RegisterAccountBadRequest](String , JsonSerializerOptions )
   at ASBNApp.Frontend.Pages.Register.HandleRegistering()
   at ASBNApp.Frontend.Pages.Register.<BuildRenderTree>b__0_6()
   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
   at MudBlazor.MudBaseButton.OnClickHandler(MouseEventArgs ev)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task , ComponentState )

我正在使用 Identity 包来实现身份验证,这就是正确的:

Microsoft.AspNetCore.Identity.EntityFrameworkCore

我认为该错误是由我的前端引起的(因为我仍然可以使用 Swagger UI 注册),但是我无法弄清楚问题可能源自何处。

有人知道可能是什么问题吗?

所有代码均可在此处开源,以防万一有帮助(忽略 ASBNApp 文件夹,该文件夹是遗留的):https://github.com/mr-woodapple/ASBNApp/tree/origin/feature/%2345_DatabaseAndCoreIdentity

c# entity-framework-core asp.net-core-identity
1个回答
0
投票

好的,我在同事的帮助下解决了这个问题。有两件事错误,不确定第一件事是否与此相关。

  1. 我的 API 没有获取数据库的连接字符串 - 没有获取我的应用程序设置(和 Azure 环境变量)中为“默认”设置的值 - 不知道为什么。我通过简单地在“ConnectionStrings”中添加另一个字符串来解决这个问题,新的字符串被很好地拾取了。
  2. API 没有作为用户添加到我的数据库中。因此,API 在技术上可以访问数据库服务器(通过 EntraID 设置),但数据库本身拒绝任何访问。解决方案是运行您可以在此处的第二步中找到的查询(我使用 Azure Data Studio 执行此操作,但您可以使用任何您想要访问数据库的内容):Microsoft Docs

希望将来能对任何人有所帮助,感谢任何试图提供帮助的人!

(您在我原来的问题中看到的错误是由于 IIS 服务器返回包含错误消息的 html 文档而导致的 - 没有任何经验,这对我没有任何帮助。)

© www.soinside.com 2019 - 2024. All rights reserved.