Ben Bu sorununuzu çözebilir, düşünüyorum:
public class ApplicationUser : IdentityUser
{
/* identity field from database */
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
[Required]
public bool Internal { get; set; }
public string UserFullName { get; set; }
public string UserEmail { get; set; }
public ApplicationUser()
: base()
{
Internal = false;
}
public ApplicationUser(string userName)
: base(userName)
{
Internal = false;
}
}
şimdi varsayılan eşleme değiştirebilirsiniz:
yılında Modeller kendi Kullanıcı modelini yeniden tanımlayabilirsiniz IdentityModels.cs \ OnModelCreating() geçersiz kılmayı ve ToTable() yöntemini kullanarak AspNet tabloları:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
// Change the name of the table to be Users instead of AspNetUsers
modelBuilder.Entity<IdentityUser>().ToTable("User");
modelBuilder.Entity<ApplicationUser>().ToTable("User");
modelBuilder.Entity<IdentityRole>().ToTable("Role");
modelBuilder.Entity<IdentityUserClaim>().ToTable("User_Claim");
modelBuilder.Entity<IdentityUserLogin>().ToTable("User_Login");
modelBuilder.Entity<IdentityUserRole>().ToTable("User_Role");
}
}
Son olarak veritabanında aşağıdaki tabloları göreceksiniz: Kullanıcı, Rol, USER_ROLE, User_Claim, USER_LOGIN yerine AspNetUsers, AspNetRoles, AspNetUsersRoles, AspNetUsersClaims, AspNetUserLogins.
Tabii Kullanıcı tablo ek alanları içerecektir: KullanıcıNo (int kimlik), İç, UserFullName ve USEREMAIL.
Gerçekten bir örnek görmek isterim. Kendi kendime uygulamayı denedim, ancak AntiFogeryToken'in başarısız olmasına sebep olan bazı kimlik sorunları ile sonuçlandı. Kendi Kullanıcı sınıfım için Microsoft.AspNet.Identity.IUser kullandığımda olur. – Martin
@Hao Kung, Yukarıdan aşağı bir örnek görmek istiyorum. Ayrıca "MyUsers" için yeni tablodan kaçınmak istiyorum. Lütfen örnekte özel alanlara sahip Rol'leri ekleyebilir misiniz? – KidCoke
@Hao Kung, bir örnek verir misiniz? – RezaRahmati