Skip to content

Instantly share code, notes, and snippets.

@xltuo
Last active September 20, 2019 11:07
Show Gist options
  • Save xltuo/544e0d310720fc1823e46bfd3bfd1ad5 to your computer and use it in GitHub Desktop.
Save xltuo/544e0d310720fc1823e46bfd3bfd1ad5 to your computer and use it in GitHub Desktop.
public class ApplicationUser : IdentityUser
{
public string Name { get; set; }
public int? Age { get; set; }
public string Sex { get; set; }
public string Desc { get; set; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// 请注意,authenticationType 必须与 CookieAuthenticationOptions.AuthenticationType 中定义的相应项匹配
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// 在此处添加自定义用户声明
return userIdentity;
}
}
public class ApplicationRole : IdentityRole
{
public string RoleName { get; set; }
public string RoleCode { get; set; }
public DateTime? CreateTime { get; set; }
public string Remark { get; set; }
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim>
{
public ApplicationDbContext() : base("DB")
{
}
public ApplicationDbContext(string nameOrConnectionString) : base(nameOrConnectionString)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<ApplicationUser>().ToTable("Users");
modelBuilder.Entity<ApplicationRole>().ToTable("Roles");
modelBuilder.Entity<IdentityUserRole>().ToTable("UserRoles");
modelBuilder.Entity<IdentityUserClaim>().ToTable("UserClaims");
modelBuilder.Entity<IdentityUserLogin>().ToTable("UserLogins");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment