I have a Blazor App for .NET using the server mode. I now want to add wasm mode to it as well. What changes are required?

Amjad Khan 41 Reputation points
2024-08-30T06:26:59.27+00:00

I started my project that uses the Blazor Server template from Visual Studio 2022 for .NET8. I now realize I want to add a wasm project to it as well so can take advantage of auto mode. What changes are required in the server project so my components can use the auto mode? Is there guidance somewhere about this?

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,612 questions
Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,596 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jerry Fu - MSFT 816 Reputation points Microsoft Vendor
    2024-08-30T09:05:38.2766667+00:00

    Hi,

    There's no guidance for this change. I suggest you start from create a brand new auto template and migrate all codes to the "server project". Making sure it works the same when you only use InterActiveServer.

    After that, you could try move same page to the client project to use auto mode. There are going to be some challenges. First is you need to make sure the services used are registered in both project to let the dependency injection work in all rendermodes (SSR/Server/WASM). Second is you may need some technique to let AuthenticationStateProvider to retrieve the user identity in WASM.

    I suggest you start from "Blazor Web App Auto/perpage with individual authentication" and make sure you understand the mechanism to proceed. https://learn.microsoft.com/en-us/aspnet/core/blazor/components/render-modes?view=aspnetcore-8.0#automatic-auto-rendering


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".  Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 66,706 Reputation points
    2024-08-30T21:43:27.92+00:00

    along with project and startup changes, you will need to replace server code (database calls, authenication, etc) with webapi calls to a server service.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.