简体   繁体   中英

Where do I put the blazor.server.js script tag in a RazorPages app?

Right now I have it at the bottom of the _Layout.cshtml layout page that is used by every other page. The problem I'm having is that pages under the Identity area throw errors in the console when navigating to Identity pages :

POST https://localhost:5001/Identity/Account/_blazor/negotiate 404

and

blazor.server.js:1 Uncaught (in promise) Error: Cannot send data if the connection is not in the 'Connected' State.

These errors make me think I'm doing something wrong with how I enable Blazor Server in my RazorPages app.

So I'm wondering, should I only have the blazor.server.js scripts on pages that are actually using Blazor? Is there a way to make it available to Areas that putting it in the Layout seems to not do?

I believe this post answers my question:

How do I use blazor server-side inside a razor component library using areas?

By default, the SignalR service uses a relative path and was unable to find the _blazor/negotiate endpoint within an Area. The suggested code change in _Layout will make it use absolute paths and normalize to /_blazor/negotiate wherever you are in the page structure.

I know this is late but incase it help others.

I got this error when I was trying to add blazor to my existing app.

I added:

<base href="~/" />

at the end of the head tag of the _layout.cshtml file found in the shared folder.

enter image description here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM