IdentityBuilder 不包含“AddEntityFrameworkStores”的定义

Raj*_*dam 6 c# asp.net-core-webapi

我正在使用 .netcore 3.1。我有以下链接:

错误图像代码

using System;

using System.Collections.Generic;

using System.Linq;

using System.Threading.Tasks;

using Microsoft.AspNetCore.Builder;

using Microsoft.AspNetCore.Hosting;

using Microsoft.AspNetCore.HttpsPolicy;

using Microsoft.AspNetCore.Mvc;

using Microsoft.Extensions.Configuration;

using Microsoft.Extensions.DependencyInjection;

using Microsoft.Extensions.Hosting;

using Microsoft.Extensions.Logging;

///using AspNetCore3JWT.Data;

using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;


using Microsoft.AspNetCore.Authentication.JwtBearer;

using Microsoft.IdentityModel.Tokens;
using Jwt.Data;

namespace Jwt
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers()
                   .AddNewtonsoftJson();

            services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            services.AddIdentity<ApplicationUser, IdentityRole>()
                   .AddEntityFrameworkStores<ApplicationDbContext>()

                .AddDefaultTokenProviders();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Sha*_*lly 17

我刚刚将一个项目升级到 .net core 3.1,并且必须将以下行更改为

services.AddDefaultIdentity<ApplicationUser>().AddEntityFrameworkStores<DBContext>();
Run Code Online (Sandbox Code Playgroud)

services.AddDefaultIdentity<ApplicationUser>().AddUserStore<DBContext>();
Run Code Online (Sandbox Code Playgroud)


小智 5

除了Microsoft.AspNetCore.Identity.EntityFrameworkCore按照@Kirk Larkin安装包外,我还必须安装包Microsoft.AspNetCore.Identity.UI