Blazor server-side app throws error: The SPA default page middleware could not return the default page '/index.html'

Viewed 1294

I found a client-side Blazor app that implements Identity here.

It works correctly, but when I turn it to server-side Blazor it throws an error:

"Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll ("The SPA default page middleware could not return the default page '/index.html' because it was not found, and no other middleware handled the request.") on CsrfTokenCookieMiddleware line 28.

I really don't know what the problem could be. I guessed the error occurs because when using server-side Blazor, more logic is handed over to the Server project instead of the Client project, and the server doesn't contain a wwwroot. Therefore I created a symlink from the wwwroot of the Server project to the wwwroot of the Client project. But that also didn't work.

Can anybody help me with this issue? I am completely stuck. The creator also doesn't know what the problem is.

1 Answers

When you do server-side rendering with blazor, that don't use the blazor.webassembly.js for bootstrap the app, instead it uses blazor.server.js.

in your index.html file which resides in wwwroot file says as below,

<script src="_framework/blazor.webassembly.js"></script>

I checked the given GitHub repo and found the above script tag. Make it to the shown as below and try,

<script src="_framework/blazor.server.js"></script>

The server-side rendering of the blazor does not run in the web assembly it runs in the asp.net core host and makes the communication with UI thread with signal R. This is the major difference between server-side rendering and client-side rendering of blazor.

Related