编程语言
首页 > 编程语言> > c# – IdentityServer4升级到.NET Core 2.0的问题(AddConfigurationStore,AddOperationalStore)

c# – IdentityServer4升级到.NET Core 2.0的问题(AddConfigurationStore,AddOperationalStore)

作者:互联网

我从.NET Core 1.1升级到.NET Core 2.0并遇到以下问题(我还升级了一些库以支持.net core 2.0)

CS1929’ConfigurationStoreOptions’不包含’UseNpgsql’的定义,并且最好的扩展方法重载’NpgsqlDbContextOptionsExtensions.UseNpgsql(DbContextOptionsBuilder,string,Action)’需要一个’DbContextOptionsBuilder’类型的接收器

Startup.cs

        services.AddIdentityServer()
            .AddSigningCredential(Certificate.Get())
            .AddAspNetIdentity<User>()
            .AddConfigurationStore(builder =>
                builder.UseNpgsql(connectionString, options =>
                    options.MigrationsAssembly(migrationsAssembly)))
            .AddOperationalStore(builder =>
                builder.UseNpgsql(connectionString, options =>
                    options.MigrationsAssembly(migrationsAssembly)));

使用UseSqlServer时的相同问题

// configure identity server with in-memory users, but EF stores for clients and resources
services.AddIdentityServer()
    .AddTemporarySigningCredential()
    .AddTestUsers(Config.GetUsers())
    .AddConfigurationStore(builder =>
        builder.UseSqlServer(connectionString, options =>
            options.MigrationsAssembly(migrationsAssembly)))
    .AddOperationalStore(builder =>
        builder.UseSqlServer(connectionString, options =>
            options.MigrationsAssembly(migrationsAssembly)));

http://docs.identityserver.io/en/release/quickstarts/8_entity_framework.html

注意:我添加了“使用Microsoft.EntityFrameworkCore;”

解决方法:

解:

        services.AddIdentityServer()
            .AddSigningCredential(Certificate.Get())
            .AddAspNetIdentity<User>()
            .AddConfigurationStore(options =>
            {
                options.ConfigureDbContext = builder =>
                    builder.UseNpgsql(connectionString,
                        sql => sql.MigrationsAssembly(migrationsAssembly));
            })
            // this adds the operational data from DB (codes, tokens, consents)
            .AddOperationalStore(options =>
            {
                options.ConfigureDbContext = builder =>
                    builder.UseNpgsql(connectionString,
                        sql => sql.MigrationsAssembly(migrationsAssembly));

                // this enables automatic token cleanup. this is optional.
                options.EnableTokenCleanup = true;
                options.TokenCleanupInterval = 30;
            });

标签:c,asp-net-mvc,postgresql,asp-net-2-0,identityserver4
来源: https://codeday.me/bug/20190715/1464998.html