dotnet / dotnet/aspnetcore

Error loading blazor webassembly application with modified base path and using a reverse proxy

Open
#52,417 3 comments 0 reactions 0 assignees View on GitHub
area-blazor feature-hot-reload Pillar: Technical Debt
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

1. Blazor webassembly application (without any blazor server side component) does not load the browser when base path is modified and reverse proxy is used.
2. However it does load properly in the browser when only base path is modified but reverse proxy is NOT used.

### Expected Behavior

The browser should have displayed the blazor home page when using the reverse proxy and when base path is modified, just as it did when using the localhost and the port number when only the base path is modified but reverse proxy is not used.

### Steps To Reproduce

1) Created a project with Blazor WebAssembly Standalone App template in VS 2022 (Version 17.8.1)

2) Based on the https://learn.microsoft.com/en-us/aspnet/core/blazor/host-and-deploy/?view=aspnetcore-8.0&tabs=visual-studio#configure-the-app-base-path, I made following changes

3) Navigated to **wwwroot/index.html** file and modified the tag from:

``

to

``

4) Navigated to **Properties/launchSettings.json** changed the https element under profiles from

```
"https": {
...
"applicationUrl": "https://localhost:7269;http://localhost:5297",
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}"
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
```

to

```
"https": {
...
"applicationUrl": "https://localhost:7269;http://localhost:5297",
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/foo/_framework/debug/ws-proxy?browser={browserInspectUri}",
"commandLineArgs": "--pathbase=/foo",
"launchUrl": "https://localhost:7269/foo",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
```

5) Note the changes or additions to launchUrl, commandLineArgs and inspectUri properties.

6) The change to inspectUri property was not discussed in the above article but I figured it out based on the exception.

7) When I ran the project in VS, browser opened with "https://localhost:7269/foo" in the address bar and the web page renders the blazor UI as expected.

8) Now to the hard part, I used a reverse proxy (namely Caddy server) to replace the host name from "localhost:7269" to "www.example.local" after mapping the latter to the 127.0.0.1 in the host file (on windows machine) and entered "https://www.example.local/foo" in a new tab.

9) At first, all blazor files seemed to be loading in the browser until dynamic module request (based on the browser dev tools/network option) was issued by https://www.example.local/foo/_framework/dotnet.runtime.8.0.0.14kkjimq5k.js for blazor-hotreload.js file with the path https://www.example.local/_framework/blazor-hotreload.js. Note that the file path for blazor-hotreload.js **did not include** the "/foo" in it while the referer file (i.e. dotnet.runtime.8.0.0.14kkjimq5k.js) **includes** "/foo" in it.

10) Needless the browser showed "An unhandled error has occurred" with Reload link to reload it again. Clicking on reload button did not solve the issue.

11) Meanwhile the web assembly project in the VS debugger showed following exception (confirming the above error assessment):

12) Another odd thing is that the request for https://www.example.local/_framework/blazor-hotreload.js results in status code 200 while the exception is shown on the server side.

### Exceptions (if any)

Server side exception is:

```
Error: One or more errors occurred. (TypeError: Failed to fetch dynamically imported module: https://www.example.local/_framework/blazor-hotreload.js)
at Jn (c:\TempCode\DummySimulation\DummySPA\DummySPA\wwwroot\foo\_framework\https:\raw.githubusercontent.com\dotnet\runtime\5535e31a712343a63f5d7d796cd874e563e5ac14\src\mono\wasm\runtime\marshal-to-js.ts:349:18)
at Ul (c:\TempCode\DummySimulation\DummySPA\DummySPA\wwwroot\foo\_framework\https:\raw.githubusercontent.com\dotnet\runtime\5535e31a712343a63f5d7d796cd874e563e5ac14\src\mono\wasm\runtime\marshal-to-js.ts:306:28)
at wasm://wasm/00b1e8b6:wasm-function[350]:0x1faca
at wasm://wasm/00b1e8b6:wasm-function[246]:0x1bf8b
at wasm://wasm/00b1e8b6:wasm-function[239]:0xf172
at wasm://wasm/00b1e8b6:wasm-function[307]:0x1e7e4
at wasm://wasm/00b1e8b6:wasm-function[328]:0x1efda
at wasm://wasm/00b1e8b6:wasm-function[218]:0xcfec
at wasm://wasm/00b1e8b6:wasm-function[774]:0x440ad
at e. (https://www.example.local/foo/_framework/dotnet.runtime.8.0.0.14kkjimq5k.js:3:214976) {superStack: {…}, stack: , message: 'One or more errors occurred. (TypeError: Fai…xample.local/_framework/blazor-hotreload.js)', Symbol(wasm js_owned_gc_handle): 70}
```

### .NET Version

8.0.100

### Anything else?

`Visual Studio 2022 (Version 17.8.1) on Windows 11`

```
.NET SDK:
Version: 8.0.100
Commit: 57efcf1350
Workload version: 8.0.100-manifests.8d38d0cc

Runtime Environment:
OS Name: Windows
OS Version: 10.0.22000
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\8.0.100\

.NET workloads installed:
Workload version: 8.0.100-manifests.8d38d0cc
[maui-windows]
Installation Source: VS 17.8.34316.72
Manifest Version: 8.0.3/8.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.maui\8.0.3\WorkloadManifest.json
Install Type: Msi

[maccatalyst]
Installation Source: VS 17.8.34316.72
Manifest Version: 17.0.8478/8.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.maccatalyst\17.0.8478\WorkloadManifest.json
Install Type: Msi

[ios]
Installation Source: VS 17.8.34316.72
Manifest Version: 17.0.8478/8.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.ios\17.0.8478\WorkloadManifest.json
Install Type: Msi

[android]
Installation Source: VS 17.8.34316.72
Manifest Version: 34.0.43/8.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.android\34.0.43\WorkloadManifest.json
Install Type: Msi

[wasm-tools]
Installation Source: VS 17.8.34316.72
Manifest Version: 8.0.0/8.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.workload.mono.toolchain.current\8.0.0\WorkloadManifest.json
Install Type: Msi

Host:
Version: 8.0.0
Architecture: x64
Commit: 5535e31a71

.NET SDKs installed:
3.1.426 [C:\Program Files\dotnet\sdk]
5.0.406 [C:\Program Files\dotnet\sdk]
5.0.408 [C:\Program Files\dotnet\sdk]
6.0.203 [C:\Program Files\dotnet\sdk]
6.0.320 [C:\Program Files\dotnet\sdk]
6.0.417 [C:\Program Files\dotnet\sdk]
7.0.203 [C:\Program Files\dotnet\sdk]
8.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 3.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.25 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.23 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.25 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.23 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.25 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
Not set

global.json file:
Not found

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.