Base solution for your next web application
Open Closed

Sync Users from ASP.NET Identity table to ASPZERO User table #8213


User avatar
0
olmy90 created

Hi, I've another ASP.NET application (using ASP.NET Identity) where I needs to sync the users between ASPZERO project and trhe other ASP.NET application (using ASP.NET Identity). What would be a way to do this ? Any hints for me? Thanks!


8 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    There is a correspondence between identity and zero tables. You can compare some differences between them, such as TenantId. Then synchronize them.

    | Abp Tables | Identity Tables | | --- | --- | |AbpUsers|AspNetUsers| |AbpUserClaims|AspNetUserLogins| |AbpUserTokens|AspNetUserTokens| |AbpUserLogins|AspNetUserLogins| |AbpUserRoles|AspNetUserRoles| |AbpRoles|AspNetRoles| |AbpRoleClaims|AspNetRoleClaims|

    AbpUserAccounts => When someone uses DB per tenant architecture, some of tenant's user tables will be stored in a seperate database. In this case, it is hard to query all users in the whole system.

    UserAccounts table is a copy of all tenant's users tables stored in host database. In this way we can query all users from a single table at once. We have used this for linking users to each other.

  • User Avatar
    0
    olmy90 created

    Thanks for the feedback - it is very helpful.

    I just to need to sync AspNetUsers with AbpUserAccounts then.

    Anyway - which Id would be the syncing Id - there are different datatypes.

    [AbpUserAccounts]( [Id] [bigint] IDENTITY(1,1) NOT NULL,

    [AspNetUsers]( [Id] nvarchar NOT NULL

    ?
    
  • User Avatar
    0
    maliming created
    Support Team

    The abp user table uses long as the primary key type. This cannot be changed.

    You may be using string as the primary key type for the user table.(https://docs.microsoft.com/en-us/aspnet/identity/overview/extensibility/change-primary-key-for-users-in-aspnet-identity)

    So you can convert the string to long during synchronization.

    You need to store these mapping because other tables may need it, such as AbpUserClaims etc.

    | AspNetUsers | AbpUsers | | --- | --- | |e317bce5-1a6e-443c-8b9f-6e346962bb60 | 1 | |2b52c5a0-48c3-43ff-bf7a-7abcfa399fe4 | 2 |

  • User Avatar
    0
    olmy90 created

    ok thanks - I'll create own mapping table with these two fields - this should work then...

    AspNetUsers AbpUsers e317bce5-1a6e-443c-8b9f-6e346962bb60 1 2b52c5a0-48c3-43ff-bf7a-7abcfa399fe4 2

  • User Avatar
    0
    olmy90 created

    Last question - in AspNetUsers there is no tenant ID - in our ASP.NET application we can assign a user to different tenants. In AbpUsers this is not possible?

  • User Avatar
    0
    olmy90 created

    Last question - in AspNetUsers there is no tenant ID - in our ASP.NET application we can assign a user to different tenants. In AbpUsers this is not possible?

  • User Avatar
    0
    olmy90 created

    Last question - in AspNetUsers there is no tenant ID - in our ASP.NET application we can assign a user to different tenants. In AbpUsers this is not possible?

  • User Avatar
    0
    maliming created
    Support Team

    AbpUsers table hava TenantId column. You can assign a value to the user's TenantId when synchronizing it according to the actual situation.