Home > Mobile >  Asp.net Server application is working on localhost, but not in Azure (Unhandled exception rendering
Asp.net Server application is working on localhost, but not in Azure (Unhandled exception rendering

Time:04-11

I have created a web application and it is my first time to bring it live into Azure. I have followed all the steps and got SQL with all the connection strings and so on. I am able to access my application from web address. However once I am trying to login or register from web, I am getting an exception.

What I have done:

Opened appsettings.json in my solution in Visual Studio and added connection string to Azure SQL. Then run my application in Debug mode on my computer and tried to register a new user => everything worked! So If I am accessing Azure SQL from my computer (https://localhost:7113/login) everything works fine, I am able to read and write into database. If I do the same from https://xxx.azurewebsites.net/login I am getting errors mentioned below. Any ideas why it is so and how to fix?

Has it something to do with setting ap API routing?

My 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
    }
  }
}

I am having solution model build this way: Client, Server, Shared

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 , 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 at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& , JsonReaderException ) 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& ) at System.Text.Json.JsonSerializer.ReadCore[LoginResult](JsonConverter , Utf8JsonReader& , JsonSerializerOptions , ReadStack& ) at System.Text.Json.JsonSerializer.ReadCore[LoginResult](JsonReaderState& , Boolean , ReadOnlySpan1 , JsonSerializerOptions , ReadStack& , JsonConverter ) at System.Text.Json.JsonSerializer.ContinueDeserialize[LoginResult](ReadBufferState& , JsonReaderState& , ReadStack& , JsonConverter , JsonSerializerOptions ) at System.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() at MDashWeb.Client.Services.Implementations.AuthorizeApi.Login(LoginModel loginModel) at MDashWeb.Client.Pages.Authentication.Login.OnSubmit() at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task) at AntDesign.Form`1.d__128[[MDashWeb.Shared.Authorization.LoginModel, MDashWeb.Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext() at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task) at Microsoft.AspNetCore.Components.Forms.EditForm.HandleSubmitAsync()
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task) at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task , ComponentState )

I am wondering is this something similar?: https://github.com/dotnet/aspnetcore/issues/29162


I have AuthorizeApi.cs in CLient project with following:

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

Then in Server project I have Controller with following code:

[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,
  };

...

CodePudding user response:

Thank You Henk Holterman for pointing the OP in the right direction. Posted your valuable discussion as an Answer to help other community members.

Glad the user LG3 for resolved his issue by going to the Log Stream which shows all the exceptions and their details which shows you that you're pointing to an incorrect file path and mentioning the reference gives the resolution of this kind of errors and as the same suggested by the Henk Holterman user in another way to check the exact URL from the browser dev tools of api/Authorize/Register call.

  • Related