【发布时间】:2018-11-30 07:51:54
【问题描述】:
我将 IdentityRole 用户键自定义为 int 而不是 string。这就是我尝试将其添加到服务集合的方式。
首先我的应用程序用户继承自 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;
}
现在当我使用 swagger 运行时,我收到以下错误:
处理请求时发生未处理的异常 Microsoft.AspNetCore.Identnty.RoleManager 类型的解析服务 尝试激活时 Myprog.Areas.Account.Controllers.RegisterController
【问题讨论】:
标签: c# asp.net-mvc asp.net-identity asp.net-core-2.0