如何将自定义TUser和TRole添加到ASP.NET Core中的services.AddIdentity中?

时间:2017-02-21 16:18:44

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

我在

中的下一个代码中有错误
public void ConfigureServices(IServiceCollection services)

    services.AddIdentity<ApsUser, ApsRole>(option =>
        {
            option.Password.RequiredLength = 6;
        })
  

GenericArguments [0],'project.Core.Users.ApsUser','Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore`9 [TUser,TRole,TContext,TKey,TUserClaim,TUserRole,TUserLogin,TUserToken,TRoleClaim] '违反了类型参数'TUser'的约束。

我的班级

public class ApsUser : IdentityUser<int, UserClaim, UserRole, UserLogin>, IEntity
{
    public UserState State { get; set; }

    #region IEntityLogFields



    #endregion

}

public class UserRole : IdentityUserRole<int>, IEntity<int>
{
    public int Id { get; set; }

    #region IEntityLogFields



    #endregion

}

如何解决错误?

1 个答案:

答案 0 :(得分:0)

临时我做了这个

  1. 用户和角色

    public class ApsUser : IdentityUser<int>, IEntity

    公共类ApsRole:IdentityRole,IEntityLog

  2. startup.cs

    services.AddIdentity(option =&gt;         {             option.Password.RequiredLength = 6;             option.Password.RequireLowercase = false;             option.Password.RequireNonAlphanumeric = false;             option.Password.RequireUppercase = false;             option.Password.RequireNonAlphanumeric = false;

        })
            .AddEntityFrameworkStores<ApContext, int>()
            .AddDefaultTokenProviders();