我们使用 sitecore 来管理我们的注册用户(外联网域),在创建新的虚拟用户时,我们使用 Profile.Email
属性为其提供电子邮件,然后调用 Profile.Save( )
方法。
其他地方的另一个属性读取userProfile.Email
,一开始一切都很好。
另外,我们使用带有“记住我”功能的表单例份验证。
问题是,当我们关闭浏览器并重新打开它时,Sitecore.Context.User
包含有关单击“记住我”的实际用户的信息,但 User.Profile
的电子邮件始终为空。
我尝试了 Reload()
和 initialize()
它们不起作用。我还尝试通过用户名 (User.FromName()
) 再次获取用户,但返回的用户对象也没有个人资料电子邮件。
哪里做错了?
最佳答案
Security API Cookbook中有一个非常重要的评论。它与 Sitecore 6 相关,但据我所知它应该与 Sitecore 8 一起使用,因为安全模型没有重大变化。它适用于 Sitecore 7 .
Important You must log in a virtual user only after you assign Roles and Profile properties to them. The Roles and Profile properties that are assigned after logging in are lost upon subsequent request.
Sitecore.Security.Accounts.User user =
Sitecore.Security.Authentication.AuthenticationManager.BuildVirtualUser(@"domain\user"
, true);
if (user != null)
{
string domainRole = @"domain\role";
if (Sitecore.Security.Accounts.Role.Exists(domainRole))
{
user.Roles.Add(Role.FromName(domainRole));
}
user.Profile.Email = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="710402140331151e1c10181f5f121e1c" rel="noreferrer noopener nofollow">[email protected]</a>";
user.Profile[“Custom Property”] = “Custom Value”;
user.Profile.Save();
Sitecore.Security.Authentication.AuthenticationManager.LoginVirtualUser(user);
}
关于sitecore - 将 SitecoreUser.Profile 与表单例份验证结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37248190/