C
C#14mo ago
Levis

ASP.NET Core 8 Web API, can't use additional fields with Identity registration

Hello, It's my first time using Identity, so I came across some issues. When I input json data necessary to register User, it doesn't recongize anything but email and password. (puts null in every other field). I couldn't find the source of the issue, but I think I have to somehow override the registration controller, but I don't know how. (Do I just create separate controller, or can I configure it from program.cs)
7 Replies
Levis
LevisOP14mo ago
This is my model:
public class User : IdentityUser
{
public int Id { get; set; }
public string Name { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string? Facebook { get; set; }
public string? Instagram { get; set; }
public string? WhatsApp { get; set; }
public string Location { get; set; }
public ICollection<Product> Products { get; set; }
}
public class User : IdentityUser
{
public int Id { get; set; }
public string Name { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string? Facebook { get; set; }
public string? Instagram { get; set; }
public string? WhatsApp { get; set; }
public string Location { get; set; }
public ICollection<Product> Products { get; set; }
}
DbContext:
public class DataContext : IdentityDbContext<User>
{
public DataContext(DbContextOptions<DataContext> options) : base(options)
{

}

public DbSet<Product> Products { get; set; }
public DbSet<Category> Categories { get; set; }
public DbSet<Models.Type> Types { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);

modelBuilder.Entity<Product>()
.HasOne(p => p.Seller)
.WithMany(u => u.Products)
.HasForeignKey(p => p.SellerId);
}
}
public class DataContext : IdentityDbContext<User>
{
public DataContext(DbContextOptions<DataContext> options) : base(options)
{

}

public DbSet<Product> Products { get; set; }
public DbSet<Category> Categories { get; set; }
public DbSet<Models.Type> Types { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);

modelBuilder.Entity<Product>()
.HasOne(p => p.Seller)
.WithMany(u => u.Products)
.HasForeignKey(p => p.SellerId);
}
}
Levis
LevisOP14mo ago
Program.cs:
No description
Unknown User
Unknown User14mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX14mo ago
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
Levis
LevisOP14mo ago
BlazeBin - ymyvswkhhaio
A tool for sharing your source code with the world!
Subbz
Subbz14mo ago
The MapIdentityApi<User> extension method only adds email and password when registering, as it takes a RegisterRequest containing only those two properties. You'd have to write you own from another controller, and accept whatever you need. You can F12 over the MapIdentityApi<User> to see see the register method.
Levis
LevisOP14mo ago
Thanks, that's exactly what I was looking for

Did you find this page helpful?