我正在构建一个与 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
好的,我在同事的帮助下解决了这个问题。有两件事错误,不确定第一件事是否与此相关。
希望将来能对任何人有所帮助,感谢任何试图提供帮助的人!
(您在我原来的问题中看到的错误是由于 IIS 服务器返回包含错误消息的 html 文档而导致的 - 没有任何经验,这对我没有任何帮助。)