On the issue of multiple users being tied to a single contact.

YUTA TAKADA asked on August 10, 2021 06:31

Hi

A problem has occurred where multiple records with the same ContactID exist in the Membership table.

There are multiple Users associated with a single Contact.

Since multiple users are associated with a single contact, we are having trouble identifying the user in some ActivityLogs.

I have two questions on the above issue.

【Question1】 What are some possible reasons for the above problem to occur?

【Question2】 I would like to know how to modify the records with the same ContactID that currently exist.

Best regards,


Kentico:v12.0.91 Azure:Webapp

Recent Answers


Dmitry Bastron answered on August 10, 2021 06:56

Hi Yuta,

I'd recommend reading through this short thread about just the same problem.

Tl;dr: if multiple users from the same pc without clearing the cookies log into your Kentico website, they will be mapped to the same contact. This mapping is stored within OM_Membership table and here is the query to show users mapped to contacts where you can find duplicate records:

select *
from CMS_User u
inner join OM_Membership m on m.RelatedID = u.UserID
inner join OM_Contact c on m.ContactID = c.ContactID
where m.MemberType = 0

This login mapping behaviour is by default. To stop this from happening you'd need to implement your custom logic via ICurrentUserContactProvider, in particular GetContactForCurrentUserAndContact method.

In terms of resolving the existing records, I'm afraid this needs to be done manually via SQL script. Basically, find your duplicates with the script above and delete records from OM_Membership table respectively.

1 votesVote for this answer Mark as a Correct answer

YUTA TAKADA answered on August 10, 2021 08:12

Hi Dmitry.

Thank you for your quick response.

I now understand why the problem occurred.

Is it correct that the records that have already been created in the Membership table will be created with different ContactIDs by modifying the following steps?

[Procedure]

  1. Delete duplicate records from the Membership table.
  2. Log in to the site as the user of the deleted record. Before logging in, delete the cookies.

Also, if it is difficult to fix the problem using the above method for a specific reason, is it possible to manually link the user to the contact from the database? If it is possible, I would appreciate it if you could provide me with the procedure.

0 votesVote for this answer Mark as a Correct answer

David Rossall answered on August 11, 2021 15:47

Regarding why it happens, that will depend a lot on your system, I'm sure. However, for us, it can happen when a member of staff both registers as a Web-site user (which is desirable, because we want staff to see the experience of users), and is assigned an editor/administrator account in the Kentico CMS. If the administrator account is created first, it's fine and both can co-exist without problems. That's desirable because it allows staff to use their work email accounts for both purposes. If the user account is created first, it doesn't work because Kentico rejects the administrator account as a duplicate. But we've been running for a year and not yet noticed any problems caused by the duplicates created by the first route above - indeed, it's an advantage, for the reasons stated. Staff using the second route need to find an external email account, or use a personal one, in connection with editing work.

Personally, I understand why one would use a single, combined user database for users and administrators on an intranet. However, I have always felt it to be a mistake for public Web sites. I want to be able to visit the site both as a signed-in user and as a visitor while editing, and I don't want any rights that I may have as administrator to interfere with what I see when I do. But Kentico is like other CMSs in choosing the combined route.

0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on August 13, 2021 10:47

Hi Yuta,

Sorry for the delay. The following SQL query will show you your duplicate records:

select u.UserID,
   u.UserName,
   u.Email as 'UserEmail',
   c.ContactID,
   c.ContactEmail,
   m.MemberType,
   m.MembershipID
from CMS_User u
     inner join OM_Membership m on m.RelatedID = u.UserID
     inner join OM_Contact c on m.ContactID = c.ContactID
where u.Email != c.ContactEmail

Then, this SQL query will delete the wrong mappings (mappings where Contact email is different from user email):

delete
from OM_Membership
where MembershipID in (select m.MembershipID
                       from CMS_User u
                            inner join OM_Membership m on m.RelatedID = u.UserID
                            inner join OM_Contact c on m.ContactID = c.ContactID
                       where u.Email != c.ContactEmail)

This will not delete any users or contacts. It will only break wrong connections where user and contact emails don't match.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.