gpt4 book ai didi

c# - Asp.net 服务器应用程序正在本地主机上运行,​​但不在 Azure 中运行(未处理的异常渲染组件 : ExpectedJsonTokens)

转载 作者:行者123 更新时间:2023-12-03 07:03:59 27 4
gpt4 key购买 nike

我创建了一个 Web 应用程序,这是我第一次将其引入 Azure。我已经遵循了所有步骤并获得了包含所有连接字符串的 SQL 等等。我可以从网址访问我的应用程序。然而,一旦我尝试从网络登录或注册,我就会遇到异常。

我做了什么:

已打开appsettings.json在我的 Visual Studio 解决方案中,并将连接字符串添加到 Azure SQL。然后在我的计算机上以 Debug模式运行我的应用程序并尝试注册一个新用户=>一切正常!因此,如果我从计算机 (https://localhost:7113/login) 访问 Azure SQL,则一切正常,我可以读取和写入数据库。如果我从https://xxx.azurewebsites.net/login做同样的事情我收到下面提到的错误。有什么想法为什么会这样以及如何解决吗?

这与设置 ap API 路由有关吗?

我的launchSettings.jason:

{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:25391",
"sslPort": 44337
}
},
"profiles": {
"MaDashWeb.Server": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:7113;http://localhost:5113",
"dotnetRunMessages": true
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Docker": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
"publishAllPorts": true,
"useSSL": true
}
}
}

我正在以这种方式构建解决方案模型:客户端、服务器、共享

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. atSystem.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader&, ExceptionResource , Byte , ReadOnlySpan1 ) at System.Text.Json.Utf8JsonReader.Read() at System.Text.Json.Serialization.JsonConverter1[[MDashWeb.Shared.Authorization.LoginResult,MDashWeb.Shared, Version=1.0.0.0, Culture=neutral,PublicKeyToken=null]].ReadCore(Utf8JsonReader& , JsonSerializerOptions, ReadStack& ) Exception_EndOfInnerExceptionStack atSystem.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& ,JsonReaderException ) atSystem.Text.Json.Serialization.JsonConverter1[[MDashWeb.Shared.Authorization.LoginResult, MDashWeb.Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].ReadCore(Utf8JsonReader& , JsonSerializerOptions , ReadStack& ) at System.Text.Json.JsonSerializer.ReadCore[LoginResult](JsonConverter , Utf8JsonReader& , JsonSerializerOptions , ReadStack& ) at System.Text.Json.JsonSerializer.ReadCore[LoginResult](JsonReaderState& , Boolean , ReadOnlySpan1 , JsonSerializerOptions , ReadStack& ,JsonConverter ) atSystem.Text.Json.JsonSerializer.ContinueDeserialize[LoginResult](ReadBufferState&, JsonReaderState& , ReadStack& , JsonConverter ,JsonSerializerOptions ) atSystem.Text.Json.JsonSerializer.d__651[[MDashWeb.Shared.Authorization.LoginResult, MDashWeb.Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext() at System.Net.Http.Json.HttpContentJsonExtensions.<ReadFromJsonAsyncCore>d__41[[MDashWeb.Shared.Authorization.LoginResult,MDashWeb.Shared, Version=1.0.0.0, Culture=neutral,PublicKeyToken=null]].MoveNext() atMDashWeb.Client.Services.Implementations.AuthorizeApi.Login(LoginModelloginModel) atMDashWeb.Client.Pages.Authentication.Login.OnSubmit() atMicrosoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Tasktask) atAntDesign.Form`1.d__128[[MDashWeb.Shared.Authorization.LoginModel,MDashWeb.Shared, Version=1.0.0.0, Culture=neutral,PublicKeyToken=null]].MoveNext() atMicrosoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Tasktask) atMicrosoft.AspNetCore.Components.Forms.EditForm.HandleSubmitAsync()
atMicrosoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Tasktask) atMicrosoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task, ComponentState )

我想知道这是否类似?:https://github.com/dotnet/aspnetcore/issues/29162

<小时/>

我在 CLient 项目中有 AuthorizeApi.cs,内容如下:

public async Task<RegisterResult> Register(RegisterModel registerModel)
{
HttpResponseMessage response = await this.HttpClient.PostAsJsonAsync("api/Authorize/Register", registerModel);
return await response.Content.ReadFromJsonAsync<RegisterResult>();
}

然后在服务器项目中我有带有以下代码的 Controller :

[Route("api/[controller]/[action]")]
[ApiController]
public class AuthorizeController : ControllerBase

...

[HttpPost]
public async Task<IActionResult> Register([FromBody] RegisterModel model)
{
ApplicationUser newUser = new ApplicationUser
{
UserName = model.Email,
Email = model.Email,
FirstName = model.FirstName,
LastName = model.LastName,
};

...

最佳答案

谢谢Henk Holterman为 OP 指明正确的方向。将您宝贵的讨论作为答案发布,以帮助其他社区成员。

很高兴用户LG3通过转到日志流来解决他的问题,该日志流显示所有异常及其详细信息,这表明您指向了错误的文件路径并提到 reference给出了此类错误的解决方案,并且与 Henk Holterman 用户建议的相同,以另一种方式从 api/Authorize/Register 的浏览器开发工具检查准确的 URL> 打电话。

关于c# - Asp.net 服务器应用程序正在本地主机上运行,​​但不在 Azure 中运行(未处理的异常渲染组件 : ExpectedJsonTokens),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71779943/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com