我使用ASP.Net Core2 Identity和Identity Server4来管理我的应用程序的用户和登录。
我使用以下代码按照documentation配置Kestrel托管的Identity Server:
var host = new WebHostBuilder().UseKestrel()
.UseUrls("http://localhost:44333")
.UseStartup<IdentityStartup>();
host.Build().Start();IdentityStartup包含以下ASP.Net核心身份设置:
services.AddIdentity<UserAccount, Role>()
.AddEngineEntityFrameworkStores<IdentityDBContext>();
services.AddDataProtection().PersistKeysToFileSystem(new DirectoryInfo(@"D:\"));当网络主机运行时,我在_getPolicyRegKey委托的Asp.Net核心标识中的RegistryPolicyResolver中获得了一个空引用异常,特别是在使用以下命令读取注册表项时:
_getPolicyRegKey = () => Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\DotNetPackages\Microsoft.AspNetCore.DataProtection");通过下载微软的符号,我可以看到Registry.LocalMachine返回了null,给出了这一行的异常。
有没有办法让Registry.LocalMachine返回一个正确的值,或者,最好是,有没有办法一起覆盖或关闭注册表?
我注意到IRegistryPolicyResolver是内部的,所以我可以添加它的自己的版本,而DataProtectionServiceCollectionExtensions中的AddDataProtectionServices是私有的,并且总是被调用,所以我不能覆盖它
发布于 2017-10-08 20:42:12
根据documentation的说法
警告
如果更改密钥持久化位置,系统将不再自动加密静态密钥,因为它不知道DPAPI是否是合适的加密机制。
this doc说:
说明
如果您指定了显式的静态密钥加密机制,数据保护系统将注销启发式提供的默认密钥存储机制。必须指定显式密钥存储机制,否则数据保护系统将无法启动。
我不能确定这就是您遇到的问题(看起来更像是您发现了一个bug),但是文档中规定的解决方案(至少对于第一个问题)是使用ProtectKeysWith*方法之一:
services.AddDataProtection()
.PersistKeysToFileSystem(new DirectoryInfo(@"D:\"))
// searches the cert store for the cert with this thumbprint
.ProtectKeysWithCertificate("3BCE558E2AD3E0E34A7743EAB5AEA2A9BD2575A0");或
services.AddDataProtection()
.PersistKeysToFileSystem(new DirectoryInfo(@"D:\"))
// all user accounts on the machine can decrypt the keys
.ProtectKeysWithDpapi(protectToLocalMachine: true);https://stackoverflow.com/questions/46630228
复制相似问题