简体   繁体   English

如何判断代码是否将在客户端或服务器上运行 Blazor?

[英]How can I tell if code will run on the client or server with Blazor?

I am new to Blazor development and I'm probably missing something obvious here, but searching google, reading documentation and searching this site has not turned up an answer for me.我是 Blazor 开发的新手,我可能在这里遗漏了一些明显的东西,但是搜索谷歌、阅读文档和搜索这个网站并没有为我找到答案。

I have some code that I need to ensure is run server-side for security reasons (hashing passwords for example).出于安全原因(例如散列密码),我需要确保在服务器端运行一些代码。 I know Blazor typically determines automatically where code will be run, but in this situation can I ensure that some functions are run in the client and some server-side?我知道 Blazor 通常会自动确定代码将在哪里运行,但是在这种情况下,我可以确保某些功能在客户端和某些服务器端运行吗?

Blazor Server is the application model where all code is run on the server, including Blazor UI components and related code. Blazor 服务器是应用程序 model,所有代码都在服务器上运行,包括 Blazor UI 组件和相关代码。 This is translated into HTML diff messages which are sent via a SignalR.这被转换为通过 SignalR 发送的 HTML 差异消息。

Blazor WASM (WebAssembly) is where Blazor UI components are downloaded to, and run on the client. Blazor WASM (WebAssembly) 是 Blazor UI 组件下载到并在客户端上运行的地方。 So any sensitive or confidential code should not be included in that project.因此,任何敏感或机密代码都不应包含在该项目中。

The selection between the two is initially done when selecting the project type:两者之间的选择最初是在选择项目类型时完成的: 在此处输入图像描述

If you have a Blazor WASM application then you can decide to run certain functions on the server if you wish.如果您有 Blazor WASM 应用程序,那么您可以根据需要决定在服务器上运行某些功能。 The standard "ASP.NET Core hosted" example does this by implementing the weather forecast service as a Web API method (see WeatherForecastController.cs ).标准的“ASP.NET Core 托管”示例通过将天气预报服务实现为 Web API 方法来实现这一点(请参阅WeatherForecastController.cs )。

You can safely host code in the ASP.NET Core server application where it is never accessible to the client, except via the methods you provide, eg Web API methods.您可以安全地在 ASP.NET 核心服务器应用程序中托管代码,除非通过您提供的方法,例如 Web API 方法,客户端永远无法访问它。

Anything to do with security or validation is a good example.任何与安全或验证有关的事情都是一个很好的例子。 Any password hashing code should always be on the server and never on the client.任何密码散列代码都应该始终在服务器上,而不是在客户端上。

Hope this helps clear it up希望这有助于清除它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何判断 blazor 中是否存在元素引用 - How can I tell if an element reference does exist in blazor 如何为实际连接到我的 Blazor 服务器应用程序的每个客户端分配一个单独的“客户端连接号”? - How can I assign for each client that is actualy connected to my Blazor server app a seperate "Client-connection-number"? NetworkCommsDotNet,如何在此代码中反转TCP客户端和服务器功能? - NetworkCommsDotNet , how can I reverse TCP client and server functions in this code? 如何在 Blazor 服务器端的 CircuitHandler 中调用方法? - How can I invoke method in CircuitHandler of Blazor server-side? 如何从 Blazor 服务器中的页面处理(销毁)组件? - How can I dispose (destroy) a component from a page in Blazor Server? 如何从 Blazor 服务器写入浏览器控制台 - How can I write to browser console from Blazor Server 如何判断.Net 3.5垃圾收集器是否已运行? - How can I tell if the .Net 3.5 garbage collector has run? 我如何在运行时知道哪个控件在前面? - How can I tell at run-time which control is in front? 如何在 Blazor WebAssembly 中登录时运行代码? - How to run code on login in Blazor WebAssembly? 如何判断 SQL 服务器已启动并可以使用? - How can I tell that SQL Server is started and ready to use?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM