asp.net-core - 在 dotnet core 2.0 中实现自定义 key 存储库

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

要在 dotnet core 1.1 中管理 Cookie 的 DataProtection,建议的一种方法是将 IXmlRepository 实现为自定义 key 存储提供程序,并在 Startup.cs 中按如下方式进行连接:

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

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

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

我错过了什么?

最佳答案

你可以试试这个:

using Microsoft.AspNetCore.DataProtection.KeyManagement;

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

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

关于asp.net-core - 在 dotnet core 2.0 中实现自定义 key 存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45821413/

相关文章:

asp.net - ILoggingBuilder 没有参数为 0 的 AddEventSourceLogger。如何初始化此日志记录

json - 如何让 bootswatch 主题与我的 Gruntfile.js 一起使用?

viewmodel - MVC 6 复杂模型绑定(bind)

c# - 如何在 Asp.Net Core 中注册同一接口(interface)的多个实现?

c# - 为什么 Visual Studio 告诉我未定义 AddJsonFile() 方法?

c# - 方法 'UseRouting' 没有重载需要 1 个参数

linux - 有没有办法检查和清理在 Linux 下运行的 ASP.NET Core 应用程序的证书吊销列表缓存?

c# - 如何在 Asp.net MVC 6 中使用 NHaml(找不到模板错误)

c# - 将参数传递给 ASP.NET MVC 6 中的需求/策略

c# - 图片文件上传及使用 ASP.NET Core 2.0