我需要验证来自外部服务的用户凭据,因此我使用VirtualUser
身份验证。
-
BuildVirtualUser
,检查要设置的角色,保存用户配置文件,然后使用该名称登录。
我正面临着一个问题,每天我登录,用相同的凭据Sitecore创建一个新用户的经验配置文件。
我需要改变我的代码,以确保,与虚拟用户登录,Sitecore获得用户的旧体验配置文件?
我正在考虑在sitecore中创建具有相同通用密码的用户。而不是使用虚拟用户,并通过sitecore直接进行身份验证。对吗?
下面是我的代码:
Sitecore.Security.Accounts.User user = Sitecore.Security.Authentication.AuthenticationManager.BuildVirtualUser(sitecoreUser, true);
string roleName = @"newRoleUser";
Sitecore.Security.Accounts.Role demoRole = Sitecore.Security.Accounts.Role.FromName(roleName);
if (Sitecore.Security.Accounts.Role.Exists(roleName) && !demoRole.IsMember(user, true, false))
{
user.Roles.Add(Sitecore.Security.Accounts.Role.FromName(roleName));
}
user.Profile.Name = name;
user.Profile.Email = email;
user.Profile.FullName = fullname;
user.Profile.Save();
Sitecore.Security.Authentication.AuthenticationManager.Login(user.Name);
Tracker.Initialize();
代码看起来很好,但是您错过了一个重要的事情:识别您的用户/联系人。
你需要添加下一行代码:
Tracker.Current.Session.Identify(email);
请查看下一个链接以获取更多关于如何识别联系人的信息:
https://doc.sitecore.net/sitecore_experience_platform/setting_up__maintaining/xdb/contacts/identifying_contacts