ASP.Net Core Blazor Server - Run specific methods on the client side

Adrien PROMIS 5 Reputation points
2023-08-04T13:17:57.7366667+00:00

Hi,

I'm using ASP.Net Core for a lot of my personal and business projects.

Especially, I'm often using Blazor Server for my projetcs that requires a GUI for the user experience.

Quite regularly, I find myself in a situation where all my logic is server-side but I need to run a very specific method on the client-side (ex : Encryption when E2E encryption is needed)

I know that it is possible to call Javascript function from .NET functions. In fact, it's the way I dealt with this problem until now.

Now that we have technologies like Blazor WebAssembly, which enable to run .NET logic, I was wandering if there may be a simpler way...

To be clear, I would like to keep almost all my logic server-side but to be able to divert some specific function on the client-side without having to rely on JS and while keeping all the advantages of Blazor Server.

Is this possible right now by some ways I don't know ? Or is this functionnality planned in a future evolution of the framework ?

Thanks in advance,

Sincerely,

Adrien

Developer technologies .NET Blazor
{count} vote

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2023-08-04T15:53:09.4266667+00:00

    Blazor WASM runs in a sandbox and has no access to client filesystem, dom, network, etc. It uses js interop for this. So there is nothing a Blazor WASM can do without js that Blazor server can not do. That is Blazor WASM is purely computational except for javascript message support.

    so even if you configured your Blazor server site to load a WASM, you would need javascript to call the WASM code, and the WASM code would need to call javascript to do the operation you wanted to do in the first place.

    note: not sure why you would call javascript for encryption for server side communication. this seems a security flaw.

    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.