I am using ASPNet Identity to implement security in my web application.
There is a requirements where in, I need to extend the IdentityRole and IdentityUser.
Here is my code to extend the IdentityUser.
public class ApplicationUser : IdentityUser
{
public virtual User User { get; set; }
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("name=CoreContext")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<IdentityUser>()
.ToTable("AspNetUsers");
modelBuilder.Entity<ApplicationUser>()
.ToTable("AspNetUsers");
}
}
My only problem is the IdentityRole
To extend User , Update your
ApplicationUser
class(located inIdentityModels.cs
) toTo Extend Role , Create a class
ApplicationRole.cs
and Add the class inside
IdentityConfig.cs
file :Now clear the old database, Run the application and register a user. It will create 3 more fields(Address,City,State) in AspNetUsers table and one more field(Description) into AspNetRoles table. That's it.
For more info , go to the site : Extending Identity Role
You can inherit from IdentityRole in your application the same way that you do your IdentityUser. Why do you need to extend IdentityRole? Please take a look at the following article which explains in detail what you are trying to do http://typecastexception.com/post/2014/02/13/ASPNET-MVC-5-Identity-Extending-and-Modifying-Roles.aspx