首页 新闻 会员 周边

ASP.NET Core中如何将Data Protection Key存储在redis中

1
悬赏园豆:20 [已解决问题] 解决于 2017-01-11 15:31

在 Startup.cs 的 ConfigureServices() 方法中添加  services.AddDataProtection(); 之后,Data Protection Key默认会保持在运行当前站点的用户profile文件夹中。

info: Microsoft.Extensions.DependencyInjection.DataProtectionServices[0]
      User profile is available. Using '/root/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.

请问如何保存在redis中以让多台服务器共享?

dudu的主页 dudu | 高人七级 | 园豆:30994
提问于:2017-01-01 21:14
< >
分享
最佳答案
1

aspnet/DataProtection 已经有了redis的实现,使用方法如下: 

var redisSection = Configuration.GetSection("redis");
var conf = redisSection.GetValue<string>("Configuration");
var redis = ConnectionMultiplexer.Connect(conf);
services.AddDataProtection().PersistKeysToRedis(redis, "DataProtection-Keys");

我基于 Microsoft.Extensions.Caching.Distributed 中的 IDistributedCache 实现了一个 DistributedStoreXmlRepository,使用方法如下:

var redisSection = Configuration.GetSection("redis");
services.AddDistributedRedisCache(options => redisSection.Bind(options));
services.AddDataProtection().PersistKeysToDistributedStore();

最终通过 DataProtection.DistributedStore 与 ServiceStackRedisCache 实现的。

dudu | 高人七级 |园豆:30994 | 2017-01-03 22:19
其他回答(2)
0
收获园豆:20
Savorboard | 园豆:411 (菜鸟二级) | 2017-01-02 13:33
0

Microsoft.AspNetCore.DataProtection.Redis

SpeakHero | 园豆:31 (初学一级) | 2018-10-30 16:59
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册