我创建了一个aspnet核心Web应用程序,并安装了IdentityServer4和IdentityServer4.EntityFramework包,以便为客户端和资源配置而不是inMemory使用数据库存储。但是,当我在services集合中添加ConfigurationDbContext和PersistedGrantDbContext时,如下图所示 我得到一个例外说明"无法解析类型' IdentityServer4.EntityFramework.Options.OperationalStoreOptions'尝试激活IdentityServer4.EntityFramework.DbContexts.PersistedGrantDbContext'。" 如
下面的命令行截图所示如何修复抛出的异常
答案 0 :(得分:2)
如何解决此问题
首先,我在第一个屏幕截图中删除了我手动添加的DbContexts,它来自第49行到第53行。
其次,在添加.AddSigningCredentials()
加载证书时我犯了一个错误,我应该使用IHostingEnvironment
来获取我的证书的ContentRootPath。因此,将.AddSigningCredentials(..)
更改为:
.AddSigningCredential(new X509Certificate2(Path.Combine(_environment.ContentRootPath,
"sample-cert.pfx"), "password")
添加这就是我如何解决抛出的异常并处理我想要的迁移。
答案 1 :(得分:2)
我通过在StartUp.cs文件中添加以下行来掩盖此错误
public void ConfigureServices(IServiceCollection services)
{
var storeOptions = new ConfigurationStoreOptions();
services.AddSingleton(storeOptions);
}
希望对您也有帮助