在dotnet core 2.0中实现自定义密钥存储库

时间:2017-08-22 15:14:34

标签: asp.net-core asp.net-core-mvc

要管理dotnet核心1.1中的Cookie的DataProtection,一种推荐的方法是将IXmlRepository实现为自定义密钥存储提供程序,并在Startup.cs中将其连接如下:

services.AddSingleton<IXmlRepository>(new MyCustomXmlRepository());

升级到dotnet core 2.0后,我的存储库中不再调用GetAllElements()HttpContext.User.Identity.IsAuthenticated始终为false。

文档总是含糊不清(https://docs.microsoft.com/en-us/aspnet/core/security/data-protection/implementation/key-storage-providers),但仍然暗示这种方法仍然有效。

我错过了什么?

1 个答案:

答案 0 :(得分:2)

你可以试试这个:

using Microsoft.AspNetCore.DataProtection.KeyManagement;

services.Configure<KeyManagementOptions>(options =>
{
    options.XmlRepository = new MyCustomXmlRepository();
});

来源:https://github.com/aspnet/DataProtection/issues/251