Open BinaryFly opened 2 hours ago
@BinaryFly thanks for contacting us.
If you turn on detailedErrors
and turn the logging level all the way to debug
what do you see on the server logs?
Hi @BinaryFly. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
Motivation
I have a .NET 8 Blazor server app where I wish to change the base url for. This is because I need to deploy my application to IIS and it will be locally hosted using a reverse proxy. "Why do you need to change the base url for this?" I hear you asking. Well eventually there should be multiple blazor applications that are all locally hosted and served via a reverse proxy on the same machine, and I distinguish these applications using their base path.
^root/car(.*)
->http://localhost:8081{R:1}
^root/house(.*)
->http://localhost:8082{R:1}
The thing is that my static files are not served correctly if I don't adjust the base path of my application. Static files would be retrieved via the root of the URL where the first html file loads in, which is localhost without a specified port (and thus will give back an error 404).
Say that for example the following is a snippet of my
App.razor
for my CarApp.Now let's say that the user calls
http://localhost/root/car
, what will happen?app.css
fromhttp://localhost/app.css
app.css
is hosted onhttp://localhost:8081/app.css
not onhttp://localhost/app.css
.A way to prevent this from happening would be to set another rewrite rule in iis to rewrite
http://localhost/app.css
(for example) tohttp://localhost:8081/app.css
. But what if we also want to load in our HouseApp, and this has itsapp.css
link specified in the same way? Then we would get back theapp.css
from our CarApp since it would be rewritten to localhost:8081.My Solution
To try and circumvent this issue, I tried setting the base path for blazor server as specified in the manual. After setting the
base
tag in myApp.razor
the static files can be retrieved from the specified base.Next to this I also set the pathbase using
app.UsePathBase
because some files will still look for the root of the url instead of taking on the base specified by thebase
html tag, andapp.UsePathBase
makes these files also be hosted on the specified path base (an example of such a file would be _framework/blazor.web.js).Lastly I also used
app.MapBlazorHub
as was explained in the documentation to make sure my signalr connection uses the right path.Using these steps would make it so static files are being served with the appropriate base path that I specified in these steps. So where we the browser first tried to retrieve
app.css
viahttp://localhost/app.css
, it will now try to retrieve it viahttp://localhost/<newpathbase>/app.css
.Issue
When using the steps I wrote above, all the files and requests are correctly retrieved and executed (see screenshot).
But unfortunately, the signalR connection can't be made.
Even when testing this locally and without using IIS or a reverse proxy, I still face the same issue. I also tried to visit the page via /root/subpath, but then I see the following:
At this point I have no idea what I'm doing wrong and how I can fix my issue, I also found many different issues vaguely relating to this, but that are maybe out of date or do not correctly fit my use case.
14065
22494
23528
31751
As an example I also created a test repo that demonstrates this issue.