そこで、私はしばらく 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 で定義されています。