0

そこで、私はしばらく Sitecore で作業しており、e-mailcampaignmanager を介して電子メールを送信するために、カスタム プロファイル プロパティのフィールド (ユーザーが入力した興味) に基づいて特定のアイテムをロードするモジュールをセットアップしました。

からプロパティを取得するとうまくいき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

ニュースレターの発送パイプライン中にコードを実行している場合、「セキュリティが無効になっている」ため、コードは機能しません。私は同じ問題を経験し、ここで説明しました

チェックを実行できるようにするには、セキュリティを再度有効にする必要があります。それは次のようなものかもしれません:

 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 に答える
0

どうやら、usermanager のユーザーのドメインが「Emailcampaignmanager」であったとしても、「extranet\」ドメインを使用する必要がありました。

string testName = @"Emailcampaign\example_at_gmail_dot_com";

になるはずだった

string testName = @"extranet\example_at_gmail_dot_com";
于 2015-03-11T10:02:45.327 に答える