DNN Forums

Ask questions about your website to get help learning DNN and help resolve issues.

Move users to main portal

Sort:
You are not authorized to post a reply.





New Around Here





    Hello, 

    We used to have a DNN site with multiple portals, however we removed all the other portals and we now just have the main portal. Now what we want is to move all the users from other portals to the main portal. Right now, when they login they get 404 because the portal that they signed up to is gone.

    What I did so far is, I went to dbo.UserPortals and I tried changing the assigned PortalID on one of the uses but I got this error.

    Is there an easy way to do this in the database?

    Thank you.






    Veteran Member





      It is not recommended to do anything in the database, but as there is no way to do this on the UI, you have no other choice. Before you start: Backup your database to be able to roll back if something unexpected happens!

      The error you get is because one (or more) of these users is already in the main portal, so you get a violation of the key UserId + PortalID. The user with UserId = 157 is obviously already registered in the portal with the PortalId 0.

      What you have to do update only those users that don't have a record with the PortalId of the main portal, and then delete all those records that have a different PortalId. Also make sure that the users are assigned to the "Registered Users" role in the main portal (see table Roles, each role is assigned to a portal, so the role "Registered Users" exists in every portal with a different ID!).

      After that, restart the application pool (important!), and check if everything is as expected.

      Happy DNNing!
      Michael

       

      Michael Tobisch
      DNN★MVP

      dnnWerk Austria
      DNN Connect





      New Around Here





        Thanks for the reply Michael.

        What exactly did you mean with this statement

        "What you have to do update only those users that don't have a record with the PortalId of the main portal"   

        What record exactly did you mean?

        And also Which tables needs to edited?






        Veteran Member





          Do you have a backup of the site with the portals still intact?

          If so, you can use the fordnn /usersexportimport module (https://github.com/fordnn/usersexportimport) to export users from the portals you've deleted and import them into the portal you are saving.
          Joe Craig
          DNN MVP
          Patapsco Research Group





          Veteran Member





            Posted By markjoeylavapie on 27 Apr 2021 03:42 PM

            What exactly did you mean with this statement

            "What you have to do update only those users that don't have a record with the PortalId of the main portal"   

            What record exactly did you mean?

            And also Which tables needs to edited?

            The table UserPortals has two fields for the primary key: UserId and PortalId - the combination of these two fields has to be unique in the table.

            If you have a user with a UserId = 150, and this user is assigned to two portals, say PortalId = 0 (main portal) and PortalId = 1, you can't change the PortalId from 1 to 0 in the second case, as this would violate the primary key constraint. Therefore you have to delete the record with UserId = 150 and PortalId = 1, so the user is only assigned to the main portal.

            If the user only has 1 record in the UserPortals table, and the PortalId is different than 0 you can change that value to 0.

            If you have more than one records for this UserId, but none of them has PortalId = 0, then you should change one of these records to PortalId = 0 and delete the other one(s).

            Hope you got the idea.

            And: Backup you database before you start any of these changes, to be able to rollback if something goes wrong.

            And: Restart the application pool after these changes.

            Happy DNNing!
            Michael

             

            Michael Tobisch
            DNN★MVP

            dnnWerk Austria
            DNN Connect





            New Around Here





              Hi Micheal,

              Thank you for the detailed instruction. I did exactly what you said, but the system keeps generating new UserPortal record for the record that I deleted. 

              Example. If  I delete UserID=4 PortalID=1 UserPortalID=123. Once the user attempted another login, the user will still be redirected to Portal 1. And a new record on the database will be generated, and this time... UserID=4 PortalID=1 UserPortalID=124






              Veteran Member





                please be aware the userportal record is not sufficient - the user also needs roles assigned and profile property values generated. Although it is possible (but requires some additional effort) to do this using SQL, it would be preferred to use DNN API methods to create the user for the new site.





                Veteran Member





                  It is most propably what Sebastian said, I mentioned this in my first post in this thread.

                  Also don't forget to restart the application pool after the changes, otherwise data is coming from the cache and does not reflect your changes.

                  Happy DNNing!
                  Michael

                  Michael Tobisch
                  DNN★MVP

                  dnnWerk Austria
                  DNN Connect
                  You are not authorized to post a reply.

                  These Forums are dedicated to the discussion of DNN Platform.

                  For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

                  1. If you have (suspected) security issues, please DO NOT post them in the forums but instead follow the official DNN security policy
                  2. No Advertising. This includes the promotion of commercial and non-commercial products or services which are not directly related to DNN.
                  3. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
                  4. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
                  5. No Flaming or Trolling.
                  6. No Profanity, Racism, or Prejudice.
                  7. Site Moderators have the final word on approving / removing a thread or post or comment.
                  8. English language posting only, please.

                  Would you like to help us?

                  Awesome! Simply post in the forums using the link below and we'll get you started.

                  Get Involved