因此,我已经在 Sitecore 工作了一段时间,为了通过电子邮件营销管理器发送电子邮件,我设置了一个模块,该模块应该根据自定义配置文件属性中的字段(用户填写的兴趣)加载某些项目。
从Sitecore.Context.User.Profile
作品中获取属性很好(所以当我以用户身份登录时,它可以工作)但是当我尝试获得它时var currentUser = Sitecore.Security.Accounts.User.FromName(Request["ec_recipient"], true);
(或用现有用户名替换 Request["ec_recipient"]),我所有的自定义属性没有价值。我试过了currentUser.Profile.Reload()
,currentUser.Profile.Initialize("username", true)
但似乎都没有。
更新
我忘了提到我已经为用户配置文件添加了一个重载,如下所示:
public class UserProfile : Sitecore.Security.UserProfile
{
/// <summary>
/// Gets or sets the interests.
/// </summary>
/// <value>
/// The interests.
/// </value>
public IList<ID> Interests
{
get
{
return string.IsNullOrWhiteSpace(this.interests)
? new List<ID>()
: this.interests
.Split(',')
.Where(ID.IsID)
.Select(g => new ID(g))
.ToList();
}
set
{
this.interests= string.Join(",", value.Select(g => g.ToString()));
}
}
/// <summary>
/// Gets or sets backingfield for the interests.
/// </summary>
/// <value>
/// The sectors.
/// </value>
private string interests
{
get
{
return this.GetCustomProperty("Interests");
}
set
{
this.SetCustomProperty("Interests", value);
}
}
}
另外,我尝试了以下方法(如评论中所述,结果仍然是空字符串)
var interests = new List<ID>();
using (new SecurityEnabler())
{
var currentUser = Sitecore.Security.Accounts.User.FromName(username, true);
using (new Sitecore.Security.Accounts.UserSwitcher(currentUser))
{
var userprofile = Sitecore.Context.User.Profile as UserProfile;
interests.AddRange(userprofile.Interests);
}
}
自定义用户配置文件在核心数据库中定义:/sitecore/templates/System/Security/Custom User 关于此主题的任何想法/帮助将不胜感激。