Base href breaks Blazor Server project
New Blazor project
Select server project
change base href on _Host.cshtml to "/myapps/first/" --note trailing slash
add app.UsePathBase("/myapps/first"); --no trailing slash
press play
--you should see blazor error display for reload
--press F12 to see console errors-- (when I press F12 it breaks in project stating IISHttpServer.cs not found)
--console displays something similiar to
Information: Normalizing '_blazor'
Information: WebSocket connected to wss://localhost:44327/myapps/first/_blazor?id=hBCsCeQnttLacpLXCT1xzw.
Error: The circuit failed to initialize.
Information: Connection disconnected.
Uncaught (in promise) Error: Invocation canceled due to the underlying connection being closed.
--All errors are for blazor.server.js
when I press F12 it breaks in project stating IISHttpServer.cs not found
Uncaught (in promise) Error: Invocation canceled due to the underlying connection being closed.
dotnet --infoRuntime Environment:
OS Name: Windows
OS Version: 10.0.17763
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk3.1.301\
Host (useful for support):
Version: 3.1.5
Commit: 65cd789777
.NET Core SDKs installed:
3.0.100 [C:\Program Files\dotnet\sdk]
3.1.102 [C:\Program Files\dotnet\sdk]
3.1.301 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.NETCore.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
@jDover01 thanks for contacting us.
Does it work without the trailing slash on the base tag?
We know for sure that this scenario works, since all our E2E tests run within a virtual subdir folder. I believe you need to specify the href without the traling slash.
I also think that you need to use app.MapWhen instead of UsePathBase, but I don't remember the specifics of the top of my head.
Based off of this site: https://docs.microsoft.com/en-us/aspnet/core/blazor/host-and-deploy/?view=aspnetcore-3.1&tabs=visual-studio it says to include the trailing slash on the base tag ("/myapps/first/"), and to use app.UsePathBase("/myapps/first") (without the trailing slash). But, I did try it without including the trailing slash. Without the trailing slash the application behaves as if the site lives @ "/myapps" NOT "/myapps/first".
I am not familiar with app.MapWhen, could you provide a sample code that I could use? The docs do not state anything about using app.MapWhen().
Again thanks for looking into this.
Thank you for filing this issue. In order for us to investigate this issue, please provide a minimalistic repro project (ideally a GitHub repo) that illustrates the problem.
@mkArtakMSFT I have created a public repository here: https://github.com/jDover01/blazorserver called BlazorApp7. Let me know if this works for you. Also noting that there was an update to Visual Studio 2019 that I downloaded and installed this morning, which changes the vs version to 16.6.3. I tried to run the application again, but still same results.
Thanks for contacting us.
We're moving this issue to the Next sprint planning milestone for future evaluation / consideration. We will evaluate the request when we will planning the work for the next milestone. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.
Hi. Thanks for contacting us.
We're closing this issue as we haven't seen many reports of it.
You can learn more about our triage process and how we handle issues by reading our Triage Process writeup.
Most helpful comment
@mkArtakMSFT I have created a public repository here: https://github.com/jDover01/blazorserver called BlazorApp7. Let me know if this works for you. Also noting that there was an update to Visual Studio 2019 that I downloaded and installed this morning, which changes the vs version to 16.6.3. I tried to run the application again, but still same results.