Skip to content

Blazor different base path produces error #57843

Closed
@roblangston

Description

@roblangston

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When you create a standard Blazor server app via the template, you receive an error if you have changed the base path within the configuration when trying to increment the counter.

page

Its a similar problem to that mentioned here: https://github.com/dotnet/aspnetcore/issues/54469. This base path behaviour is different between frameworks .Net 8 and .Net 9. In .Net 8, the blazor.web.js attempts to be downloaded from http://localhost:5165/_framework/blazor.web.js even if a different base path "blazor" has been set. In .Net 9, the file is downloaded from http://localhost:5165/blazor/_framework/blazor.web.js correctly but a different error is received when trying to interact with page components (see error).

error

The following lines have been changed in the program.cs:-

app.UsePathBase("/blazor/"); app.MapBlazorHub("/blazor"); app.UseStaticFiles("/blazor");

In App.razor, the base has been changed as follows:-

<base href="/blazor/" />

The various page routes have been prefixed to match the base path as follows:-

@page "/blazor/counter"

The reason for wanting this to work correctly is to be able to front multiple sites behind a reverse proxy, either Yarp or NginX and that behavior doesnt seem to work without the sites being deployed with a different base path.

Expected Behavior

Page functions correctly when having base path changed.

Steps To Reproduce

Create a new Blazor web project from within VS2022 Preview, make changes to the code as detailed above in the description.

GitHub repo here:-
https://github.com/roblangston/BlazorTest

Exceptions (if any)

blazor.web.js:1 [2024-09-12T18:09:34.506Z] Information: Normalizing '_blazor' to 'http://localhost:5165/blazor/_blazor'.
_blazor/negotiate?negotiateVersion=1:1

   Failed to load resource: the server responded with a status of 405 (Method Not Allowed)

blazor.web.js:1 [2024-09-12T18:09:34.509Z] Error: Failed to complete negotiation with the server: Error: Method Not Allowed: Status code '405'
log @ blazor.web.js:1
blazor.web.js:1 [2024-09-12T18:09:34.510Z] Error: Failed to start the connection: Error: Failed to complete negotiation with the server: Error: Method Not Allowed: Status code '405'
log @ blazor.web.js:1
blazor.web.js:1 [2024-09-12T18:09:34.510Z] Error: Error: Failed to complete negotiation with the server: Error: Method Not Allowed: Status code '405'
log @ blazor.web.js:1
blazor.web.js:1 Uncaught (in promise) zt: Failed to complete negotiation with the server: Error: Method Not Allowed: Status code '405'
at Dn._getNegotiationResponse (http://localhost:5165/blazor/_framework/blazor.web.js:1:87758)
at async Dn._startInternal (http://localhost:5165/blazor/_framework/blazor.web.js:1:85614)
at async Dn.start (http://localhost:5165/blazor/_framework/blazor.web.js:1:83488)
at async wn._startInternal (http://localhost:5165/blazor/_framework/blazor.web.js:1:58614)
at async wn._startWithStateTransitions (http://localhost:5165/blazor/_framework/blazor.web.js:1:58028)
at async Bo.startConnection (http://localhost:5165/blazor/_framework/blazor.web.js:1:136200)
at async Bo.startCore (http://localhost:5165/blazor/_framework/blazor.web.js:1:134228)
at async Zo (http://localhost:5165/blazor/_framework/blazor.web.js:1:153050)

.NET Version

9.0.100-rc.1.24452.12

Anything else?

1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions