Skip to content

Blazor Server should use absolute paths for blazor.server.js and for connecting to the Blazor hub #14246

Closed
@danroth27

Description

@danroth27

It looks like Blazor Server is using relative paths in a couple of places that limit when it can be used. This caused some issues when I tried to use Blazor components in an MVC app on any view other than the home page.

Repro steps:

  • Create an MVC app
  • Add services.AddServerSideBlazor() to Startup.ConfigureServices and endpoints.MapBlazorHub() in Startup.Configure.
  • Add the blazor.server.js script to the layout using the script tag we use in the Blazor Server template: <script src="_framework/blazor.server.js"></script>
  • Add a Razor component to the project with some sort of user interactivity support.
  • Add the component to the Privacy.cshtml page: @(await Html.RenderComponentAsync<MyComponent>(RenderMode.ServerPrerendered))
  • Run the app and browser to the Privacy page

Actual result:

  • The component is not interactive, because the request for blazor.server.js goes to /Home/_framework/blazor.server.js.
  • To work around this issue, update the script tag to use ~/: <script src="~/_framework/blazor.server.js"></script>. Should we do this everywhere?
  • The component is still not interactive because the SignalR client tries to connect to /Home/_blazor/. This seems like a bug we need to fix in blazor.server.js?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions