[英]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.