Sitecore虚拟用户登录体验配置文件

时间:2016-09-23 15:16:56

标签: sitecore sitecore8 sitecore-mvc

我需要验证来自外部服务的用户凭据,因此我正在使用VirtualUser身份验证。

  • BuildVirtualUser,检查要设置给他的角色,保存用户个人资料,然后使用该名称登录。

我遇到了一个问题,我每天都登录,使用相同的凭据,Sitecore会在体验资料中创建一个新用户。
我需要在代码中更改以确保通过虚拟用户登录,Sitecore获取用户的旧体验配置文件?

我在考虑使用相同的通用密码在sitecore中创建用户。而不是使用虚拟用户,并直接与sitecore进行身份验证。这是对的吗?

这是我的代码:

Sitecore.Security.Accounts.User user = Sitecore.Security.Authentication.AuthenticationManager.BuildVirtualUser(sitecoreUser, true);
string roleName = @"newRole\User";
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();

1 个答案:

答案 0 :(得分:3)

代码看起来不错,但您错过了一件重要的事情:识别您的用户/联系人。

您需要添加下一行代码:

  Tracker.Current.Session.Identify(email);

请查看下一个链接,了解有关如何识别联系人的更多信息:

https://doc.sitecore.net/sitecore_experience_platform/setting_up__maintaining/xdb/contacts/identifying_contacts

相关问题