2

I have a question, is it possible to modify IdentityUser to remove properties? there are many that I do not want. for example "PhoneNumber" or "Email".

Ty

AspNetUsers table IdentityUser class

Juan Pablo
  • 21
  • 1
  • You want to remove those fields in the table, because you dont need them? – Jonas Weinhardt Oct 01 '21 at 13:14
  • If you do not want them, do not set them, and do not use them in your code. You can rework the persistence completely if you want, but it is a lot of work. [Here is a long article on how to do it](https://learn.microsoft.com/en-us/aspnet/core/security/authentication/identity-custom-storage-providers?view=aspnetcore-5.0) – Sergey Kalinichenko Oct 01 '21 at 13:19
  • Exactly! I don't want or need those fields. – Juan Pablo Oct 01 '21 at 13:19

1 Answers1

0

Technically no, you cannot remove the properties as they are a part of the builtin package. You can extend, but not modify.

If the issue lies in the database and you want to remove the properties from the tables, yes you can

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
        base.OnModelCreating(modelBuilder);
        modelBuilder.Entity<IdentityUser>().Ignore(c => c.AccessFailedCount)
                                           .Ignore(c=> c.LockoutEnabled)
                                           .Ignore(c=>c.LockoutEndDateUtc)
                                           .Ignore(c=>c.Roles)
                                           .Ignore(c=>c.TwoFactorEnabled);//and so on...

        modelBuilder.Entity<IdentityUser>().ToTable("Users");//to change the name of table.

}

from: https://stackoverflow.com/a/38156276/3712531

Stanley
  • 2,434
  • 18
  • 28