Blazor、会话存储和弃用参考库

问题描述 投票:0回答:1

在研究在 Blazor 应用程序中实现简单的会话存储时,我发现了对 Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage 的多个引用以及似乎非常简单的实现。问题是这个组件在 nuget 中显示为已弃用,而且我找不到替代品。

@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage
@inject ProtectedSessionStorage ProtectedSessionStore

在 .Net 8 中不使用已弃用的库执行此操作的新/正确方法是什么?

c# blazor
1个回答
0
投票

要使用

ProtectedSessionStorage
,您不需要安装额外的软件包。最新的
Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage
已经在框架中
Microsoft.AspNetCore.App

enter image description here
所以直接使用你的代码就可以了。

我建议您使用

Blazored.SessionStrage
包来操作会话存储。它可以在 WASM 或服务器渲染模式下使用。但
ProtectedSessionStorage
仅在服务器项目中可用。
ProtectedBrowserStorage
会自动加密值,而
Blazored.SessionStrage
不会。不过自己实现加密并不难。

参考:https://github.com/Blazored/SessionStorage

© www.soinside.com 2019 - 2024. All rights reserved.