.net core 2.0 Resolver问题与identityrole

时间:2018-06-21 05:09:58

标签: c# asp.net-mvc asp.net-identity asp.net-core-2.0

我将IdentityRole用户密钥自定义为int而不是字符串。这就是我试图将其添加到服务集合中的方式。

首先,我的Application用户继承自identityUser

public class ApplicationUser : IdentityUser<int>......

然后在我的服务集中:

services.AddIdentity<ApplicationUser, IdentityRole<int>>(options => {
            // Password settings
            options.Password.RequireDigit = true;
            options.Password.RequiredLength = 8;.......`

在基本控制器中,我具有以下构造函数:

public BaseApiController(RoleManager<IdentityRole> roleManager, UserManager<ApplicationUser> userManager, IConfiguration configuration, ILogger<BaseApiController> logger) : base(logger)
        {
            _roleManager = roleManager;
            _userManager = userManager;
            _configuration = configuration;

            _jsonSettings = new JsonSerializerSettings() { Formatting = Formatting.Indented };
        }

然后我以以下形式在我的一个mvc控制器上使用基本控制器:

 public class RegisterController : BaseApiController
    {
        private readonly IAccountService _accountService;

        public RegisterController(RoleManager<IdentityRole> roleManager, UserManager<ApplicationUser> userManager, IConfiguration configuration, ILogger<RegisterController> logger, IAccountService accountService) : base(roleManager, userManager, configuration, logger)
        {
            _accountService =  accountService;

        }

现在当我用招摇动跑时,出现以下错误:

  

处理请求时发生未处理的异常   解决Microsoft.AspNetCore.Identnty.RoleManager类型的服务   尝试激活时   Myprog.Areas.Account.Controllers.RegisterController

1 个答案:

答案 0 :(得分:0)

基本控制器需要在调用中进行分配,然后执行所有实现:

public BaseApiController(RoleManager<IdentityRole<int>> roleManager, UserManager<ApplicationUser> userManager, IConfiguration configuration, ILogger<BaseApiController> logger) : base(logger)