0

因此,我已经在 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 关于此主题的任何想法/帮助将不胜感激。

4

3 回答 3

1

我试过了,它对我有用:

 string domainUser = @"domain\user"; 
 if (Sitecore.Security.Accounts.User.Exists(domainUser)) 
  { 
     Sitecore.Security.Accounts.User user = 
     Sitecore.Security.Accounts.User.FromName(domainUser,false); 

       using (new Sitecore.Security.Accounts.UserSwitcher(user)) 
     { 
       var property=user.Profile.GetCustomProperty("propertyname);
     } 
} 
于 2015-03-10T07:36:39.860 回答
0

所以显然,即使用户管理器中的用户域是“Emailcampaignmanager”,我也需要使用“extranet\”域。

string testName = @"Emailcampaign\example_at_gmail_dot_com";

本来应该

string testName = @"extranet\example_at_gmail_dot_com";
于 2015-03-11T10:02:45.327 回答
0

如果您在调度通讯管道期间执行您的代码,它不会工作,因为“安全被禁用”。我遇到了同样的问题并在这里解释了

您需要再次启用安全性才能进行检查。它可能是这样的:

 string testName = @"Emailcampaign\example_at_gmail_dot_com";
            //Request["ec_recipient"]
            var currentUser = Sitecore.Security.Accounts.User.FromName(testName, true);

            var interests = new List<ID>();
            using (new SecurityEnabler())
            {
                using (new Sitecore.Security.Accounts.UserSwitcher(currentUser))
                {
                    var w = currentUser.Profile.GetCustomProperty("Sectors");

                    var currentUserCustomProfile = currentUser.Profile as UserProfile;
                    currentUserCustomProfile.Initialize(testName, true);
                    currentUserCustomProfile.Reload();

                    interests.AddRange(currentUserCustomProfile.Interests);
                }
            }
于 2015-03-10T11:15:50.870 回答