2017-06-06 76 views
0

我创建了一个aspnet核心Web应用程序,并安装了IdentityServer4和IdentityServer4.EntityFramework软件包,以便将数据库存储用于客户端和资源配置,而不是inMemory。但是,当我在服务集合中添加ConfigurationDbContext和PersistedGrantDbContext时,如下图所示Image of services configuration 我收到一个异常,说“试图激活IdentityServer4.EntityFramework时无法解析类型为”IdentityServer4.EntityFramework.Options.OperationalStoreOptions“的服务。 DbContexts.PersistedGrantDbContext”。” 如被看见在命令行下面的截图commandline screenshot如何解析类型为'IdentityServer4.EntityFramework.Options.OperationalStoreOptions'的服务

如何解决异常被抛出

+0

你能澄清为什么你手动注册类型,而不是使用'services.AddIdentityServer().AddConfigurationStore(builder => ...)'扩展方法根据文档? –

+0

当我不手动时,我得到一个错误,如** No DbContext名为'PersistedGrantDbContext'找到**。如果你看第63行,我确实使用了AddConfigurationStore扩展方法,但是在添加迁移时会引发错误 –

+0

从我可以看到它应该[开箱即用](https://github.com/scottbrady91/IdentityServer4-Example/blob/master/src/ScottBrady91.IdentityServer4.Example/Startup.cs)。你确定你正在使用'AddOperationalStore'和'AddConfigurationStore'来配置你的永久存储吗? –

回答

2

如何来解决这个问题

首先我删除,我是手动添加DbContexts这是从线在第一个屏幕截图中为49到53。 其次,我在添加.AddSigningCredentials()加载证书时犯了一个错误,我应该使用IHostingEnvironment将ContentRootPath添加到我的证书中。因此改变.AddSigningCredentials(..)到:

.AddSigningCredential(new X509Certificate2(Path.Combine(_environment.ContentRootPath, 
       "sample-cert.pfx"), "password") 

添加这就是我如何解决被抛出的异常和处理,我想的迁移。

相关问题