Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UserManager` while attempting to activate 'AuthController'

前端 未结 7 1568
灰色年华
灰色年华 2020-12-05 01:53

I\'m getting this error in Login Controller.

InvalidOperationException: Unable to resolve service for type \'Microsoft.AspNetCore.Identity.UserManager

7条回答
  •  -上瘾入骨i
    2020-12-05 02:18

    You need to use the same user data model in SignInManager, UserManager and services.AddIdentity. Same principal is true if you are using your own custom application role model class.

    So, change

    services.AddIdentity(options =>
        {
            options.User.RequireUniqueEmail = false;
        })
        .AddEntityFrameworkStores()
        .AddDefaultTokenProviders();
    

    to

    services.AddIdentity(options =>
        {
            options.User.RequireUniqueEmail = false;
        })
        .AddEntityFrameworkStores()
        .AddDefaultTokenProviders();
    

提交回复
热议问题