Thus, my system requires roles to have associated expiration dates. I implemented the Identity 2.0 framework and everything runs smoothly, but I ran into a problem that makes me doubt my framework.
public class ApplicationUserRole : IdentityUserRole { public override string UserId { get; set; } public override string RoleId { get; set; } public DateTime Expiry { get; set; } } public class ApplicationDbContext : IdentityDbContext<ApplicationUser> { public ApplicationDbContext() : base("DefaultConnection", throwIfV1Schema: false) { } static ApplicationDbContext() { Database.SetInitializer<ApplicationDbContext>(null); } public static ApplicationDbContext Create() { return new ApplicationDbContext(); } public DbSet<ApplicationUserRole> ApplicationUserRoles { get; set; } }
It does what I want. It modifies the AspNetUserRoles table to add a third column, which is a DateTime called Expiry. I can add, update and delete expiration using ApplicationDBContext, everything works perfectly and well when editing users.
The problem occurs when creating an account. UserManager calls AddToRolesAsync, but accepts only two parameters: "User and role". I need him to take User, Role and Expiry.
Do I need to implement my own UserManager? This is like busting.
I can get around the problem by not allowing the choice of role / expiration when creating an account and just leaving it in edit mode. But I would really like to be able to create accounts and assign roles / expiration at the same time.
source share