ASP.NET Core Identity does not inject UserManager

后端 未结 3 1606
挽巷
挽巷 2021-01-04 05:46

I\'ve got an older asp.net core identity database, and I want to map a new project (a web api) to it.

Just for the test, I copied the Models folder, and the Applicat

3条回答
  •  星月不相逢
    2021-01-04 06:03

    Do you have the app.UseIdentity(); call in the Configure method:

     public void Configure(IApplicationBuilder app, 
                           IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            /*...*/
            app.UseIdentity();
           /*...*/          
        }
    

    EDIT Do you also have this line before the services.AddIdentity() line?

     public void ConfigureServices(IServiceCollection services)
     {
            // Add framework services.
            services.AddDbContext(options =>
                 options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
    
     }
    

    This should work OK. Also please check if ApplicationDbContext inherits from IdentityDbContext.

提交回复
热议问题