Blazor Hosted WebApp - Error after publishing

Viewed 816

I have started learning Blazor Webassembly using the Hosted model.

Locally I can create and run a simple Blazor web application using visual studio code.

However, when I publish (in this case to www.myasp.net) the following scripting error occurs on any page:

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: Unexpected token < in JSON at position 0 SyntaxError: Unexpected token < in JSON at position 0 Microsoft.JSInterop.JSException: Unexpected token < in JSON at position 0 SyntaxError: Unexpected token < in JSON at position 0 at System.Threading.Tasks.ValueTask`1[TResult].get_Result () <0x21ea748 + 0x0002c> in :0 at Microsoft.JSInterop.JSRuntimeExtensions.InvokeVoidAsync (Microsoft.JSInterop.IJSRuntime jsRuntime, System.String identifier, System.Object[] args) <0x2010058 + 0x000e4> in :0 at

Thank you

Here is the full error:

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: Unexpected token < in JSON at position 0 SyntaxError: Unexpected token < in JSON at position 0 Microsoft.JSInterop.JSException: Unexpected token < in JSON at position 0 SyntaxError: Unexpected token < in JSON at position 0 at System.Threading.Tasks.ValueTask1[TResult].get_Result () <0x21ea748 + 0x0002c> in <filename unknown>:0 at Microsoft.JSInterop.JSRuntimeExtensions.InvokeVoidAsync (Microsoft.JSInterop.IJSRuntime jsRuntime, System.String identifier, System.Object[] args) <0x2010058 + 0x000e4> in <filename unknown>:0 at Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationService3[TRemoteAuthenticationState,TAccount,TProviderOptions].EnsureAuthService () <0x20084c0 + 0x000ee> in :0 at Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationService3[TRemoteAuthenticationState,TAccount,TProviderOptions].GetAuthenticatedUser () <0x2007c20 + 0x000d2> in <filename unknown>:0 at System.Threading.Tasks.ValueTask1[TResult].get_Result () <0x21ebf88 + 0x0002c> in :0 at Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationService3[TRemoteAuthenticationState,TAccount,TProviderOptions].GetUser (System.Boolean useCache) <0x1fcb190 + 0x00136> in <filename unknown>:0 at Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationService3[TRemoteAuthenticationState,TAccount,TProviderOptions].GetAuthenticationStateAsync () <0x1fc9ff0 + 0x000d0> in :0 at Microsoft.AspNetCore.Components.Authorization.AuthorizeViewCore.OnParametersSetAsync () <0x2135338 + 0x0012e> in :0 at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion (System.Threading.Tasks.Task task) <0x2135d90 + 0x000ee> in :0 at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync () <0x1f67eb0 + 0x0020c> in :0 at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask (System.Threading.Tasks.Task taskToHandle) <0x21391a0 + 0x000ca> in :0

1 Answers

Yes,

  1. The hosting provider granted the application pool full access to the root folder (the folder just beneath the wwwroot folder) This solved the problem for me.

  2. Since I am forcing my website to use https I also had to obtain a .pfx copy of my certificate with a private key - which I then include in the appsettings.json file

  "IdentityServer": {
    "Clients": {
      "xxxxxxxxx.Client": {
        "Profile": "IdentityServerSPA"
      }
    },

    "Key": {
      "Type": "File",
      "FilePath": "xxxxxxxxx.pfx",
      "Password": "xxxxxxxxx"
    }      
  }
Related