问题描述
我一直在尝试使用UserManager和RoleManager。我实现了具有 int主键的身份类。
例如,当我想使用UserManager FindByIdAsync方法时,它仍然是必需的字符串userId参数,但是我想使用int参数。我该如何更改?实际上,我之前没有自定义UserManager或UserStore。
除了所有这些,我还使用LinqToDB.Identity。
var appUser = _userService.FindByIdAsync(); //must be used an int parameter
这是我的AppUser类。
public class AppUser : IdentityUser<int>,IEntity
{
[Required,Identity]
[Key]
public override int Id { get => base.Id; set => base.Id = value; }
public DateTime CreatedDate { get; set; }
public DateTime? ModifiedDate { get; set; }
public int? CreatedBy { get; set; }
public int? ModifiedBy { get; set; }
public int? StatusId { get; set; }
}
这是我的AddLinqToDBStores实现。
/// <summary>
/// Adds authentication service
/// </summary>
/// <param name="services">Collection of service descriptors</param>
public static void AddDevPlatformAuthentication(this IServiceCollection services,IConfiguration configuration)
{
services.AddIdentity<AppUser,AppRole>(options =>
{
options.Password.RequireDigit = true;
options.Password.RequiredLength = 4;
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireUppercase = true;
options.Password.RequireLowercase = false;
options.User.RequireUniqueEmail = true;
options.SignIn.RequireConfirmedEmail = false;
//TODO
//options.User.RequireUniqueEmail = true;
//options.Lockout.MaxFailedAccessAttempts = 5;
//options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(3);
}).AddLinqToDBStores<int,AppUserClaim,AppUserRole,AppUserLogin,AppUserToken,AppRoleClaim>(new
IdentityConnectionFactory(new SqlServerDataProvider(ProviderName.SqlServer,SqlServerVersion.v2017),"SqlServerIdentity",DataSettingsManager.LoadSettings().ConnectionString))
.AddUserStore<LinqToDB.Identity.UserStore<int,AppUser,AppRole,AppUserToken>>()
.AddUserManager<UserManager<AppUser>>()
.AddRoleManager<RoleManager<AppRole>>()
.AddDefaultTokenProviders();
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie();
// Uncomment the following lines to enable logging in with third party login providers
JwtTokenDefinitions.LoadFromConfiguration(configuration);
services.ConfigureJwtAuthentication();
services.ConfigureJwtAuthorization();
}
_userManager.FindByIdAsync()如我所说,我需要对所有userManager和roleManager方法使用 int参数。
我该如何处理?
最好的问候
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)