I've an excel sheet with list of contacts that I've uploaded to Sitecore using xconnect through stand alone console app.

                var client = new HRDataImport.ConsoleApp.XConnnectClient();

                Console.WriteLine("Step 1: Retrieve Sitecore XConnect certificate and Url from App.config");
                xconnectCertificate = ConfigurationManager.AppSettings.Get("XCONNECT_CLIENT_CERTIFICATE_THUMBPRINT");
                xconnectUrl = ConfigurationManager.AppSettings.Get("XCONNECT_CLIENT_SERVICE_URL");
                Console.WriteLine("XConnect Url: " + xconnectUrl);
                Console.WriteLine("XConnect Certificate: " + xconnectCertificate);
                // connect to xconnect and submit contact 
                Console.WriteLine("Initialize Sitecore XConnect using HRInformation Model");
                client.Initialize(xconnectCertificate, xconnectUrl).GetAwaiter().GetResult();
                Console.WriteLine("Get/Create Sitecore contact ");
                foreach (var emp in Employess)

                  Console.WriteLine("Get contactwith id :"+ emp.EmpMail);
                  var contact = client.GetContact(emp.EmpMail).GetAwaiter().GetResult();

                if (contact != null)
                    Console.WriteLine("CONTACT FOUND");
                    var personalInfo = contact.GetFacet<PersonalInformation>();

                    Console.WriteLine("personalInfo.FirstName: " + personalInfo.FirstName);
                    Console.WriteLine("personalInfo.LastName: " + personalInfo.LastName);
                    Console.WriteLine("personalInfo.JobTitle: " + personalInfo.JobTitle);

                    Console.WriteLine("NO CONTACT FOUND");
                    Console.WriteLine("Create contact, set information and submit");
                    client.SetPersonalInformation(emp.FirstName, emp.LastName, emp.JobTitle);                        
                Console.WriteLine("-------Done Emp Id --"+ emp.EmpMail);

        public async Task Submit(string identifier, string source = CONTACT_SOURCE_IDENTIFIER)
            if (_cfg == null)
                throw new Exception("Initialize must be called first.");

            using (var client = new XConnectClient(_cfg))
                // Identifier for a 'known' contact
                var contactIdentifier = new ContactIdentifier(source, identifier, ContactIdentifierType.Known);
                var identifiers = new ContactIdentifier[] { contactIdentifier };

                // Create a new contact object from the identifier
                _contact = new Contact(identifiers);
                //Add to the client
                client.SetFacet(_contact, PersonalInformation.DefaultFacetKey, personalInfo);
                client.SetFacet(_contact, EmailAddressList.DefaultFacetKey, emails);                    
                //Submit changes
                await client.SubmitAsync();

            _contact = null;

And I've done Azure AD integration to let the users sign in using their windows username/password.

Azure AD Integration

What I'm trying to do, is that after the user logs in using Azure AD to Sitecore; I need to map the existing contact to the user that is being logging in.

For reference, I've used Habitat's accounts feature and this is what I've done so far, but I'm facing lots of issues regarding the tracker and it's "isActive" is always set to false.

If you have better solution please bring it on, I don't mind starting over with the right approach.

    <processor type="Accounts.Infrastructure.Pipelines.SignedIn.TrackSignedIn, Feature.Accounts" resolve="true" />


        public override void Process(SignedInArgs args)
            var provider = this.GetProvider(args.Context.Identity);
            if (provider.Name == Sitecore.Owin.Authentication.Constants.LocalIdentityProvider)

            if (Tracker.Current == null)
          this.AccountTrackerService.TrackLoginAndIdentifyContact(provider.Name, args.User.Id);



        public virtual void TrackLoginAndIdentifyContact(string source, string identifier)
            this.trackerService.TrackGoal(LoginGoalId, source);
            this.trackerService.IdentifyContact(source, identifier);


    public void IdentifyContact(string source, string identifier)
        if (!this.IsActive) /*Tracker.Current.IsActive is Always False!!*/

        Tracker.Current.Session.IdentifyAs(source, identifier);

After solving is IsActive issue, I was going to change the identifier to match the one I used in the console app so it can map the existing contact to the logged in user.

Again this could be the wrong way, please let me know your thoughts either by solving the IsActive issue or by bringing up whole new solution.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.