sitecore - 将 SitecoreUser.Profile 与表单例份验证结合使用

标签 sitecore sitecore8

我们使用 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/

相关文章:

c# - 从 Glass.Mapper.Sitecore 升级到 Glass.Mapper.Sc 时缺少 InstanceContext

c# - 在 Sitecore 中使用 Glassmapper 映射图像

exception - Sitecore 管道错误

.net - TeamCity 不从特定包源恢复 NuGet 包

sitecore - 使用 SitecoreRocks 按 ID 搜索 Sitecore 项目

windows - 将 Sitecore PowerShell 扩展与 native PowerShell 结合使用

Sitecore Services Client vs Sitecore Web Service vs Sitecore Item web API

c# - TreeListEx,使用模板 _StandardValues 设置的字段未从 sitecore 检索?

solr - Sitecore Solr 错误未定义字段标签

installation - Sitecore 安装程序安装失败并显示错误无法打开 XML 文件,系统错误 :-2147024786