简体   繁体   中英

ASP.Net Core Identity and Profile Data

I have a few questions about where to store additional user data, such as user photo and profile data in AspNet Core Identity. The best solution is to store the address (city, region, etc.) and the user's image in a separate database table with PK as the user table's FK (to prevent the user table from growing a lot), or it's better save this additional data in user complaints?

Is the UserClaims table only for claims that come from third parties like Google, Facebook or can I use it as described above?

I hope I was clear. Thank you

The best solution is to store the address (city, region, etc.) and the user's image in a separate database table with PK as the user table's FK (to prevent the user table from growing a lot), or it's better save this additional data in user complaints?

Normally we would store profile data for the user in AspNetUsers table.

If you'd like to prevent AspNetUsers table from growing a lot, as you mentioned, using a separate table to store avatar, region and city etc user data, and establishing relationship between UserProfile and ApplicationUser is ok. But please note that it might require querying from multiple tables to get expected data.

public class UserProfile 
{
    public string UserProfileId { get; set; }

    public string City { get; set; }
   
    //...
    //other properties
    //...

    public string UserId { get; set; }

    public ApplicationUser User { get; set; }
}

Besides, AspNetUserClaims stores claims associated with an application user. We can add the specified claim to the user based on actual scenario with following code snippet.

await _userManager.AddClaimAsync(user, new Claim("type_here", "value_here"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM