Error loading blazor webassembly application with modified base path and using a reverse proxy #52417
Open
1 task done
Labels
area-blazor
Includes: Blazor, Razor Components
feature-hot-reload
This issue is related to the Hot Reload feaature
Pillar: Technical Debt
Milestone
Is there an existing issue for this?
Describe the bug
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
Created a project with Blazor WebAssembly Standalone App template in VS 2022 (Version 17.8.1)
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
Navigated to wwwroot/index.html file and modified the tag from:
<base href="/" />
to
<base href="/foo/" />
Navigated to Properties/launchSettings.json changed the https element under profiles from
Note the changes or additions to launchUrl, commandLineArgs and inspectUri properties.
The change to inspectUri property was not discussed in the above article but I figured it out based on the exception.
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.
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.
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.
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.
Meanwhile the web assembly project in the VS debugger showed following exception (confirming the above error assessment):
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:
.NET Version
8.0.100
Anything else?
Visual Studio 2022 (Version 17.8.1) on Windows 11
The text was updated successfully, but these errors were encountered: