Sitecore:如何获取当前登录用户的用户配置文件项

Sitecore: How to get the user profile item of currently logged in user

在站点核心中:

如果用户使用用户名“Addemo”登录,如何获取 /sitecore/content/Intranet/User Profiles/A/Ad/addemo.

下的用户配置文件项

我尝试使用 User.Current.Profile.ProfileItemId; 但是我得到的 ID 不是 addemo 的项目 ID (/User Profiles/A/Ad/addemo) .

Sitecore.Context.User 有个人资料 属性,你是对的。您可以通过 GetCustomProperty() 方法检索自定义配置文件值,例如:

string resetValue = Sitecore.Context.User.Profile.GetCustomProperty("Has Password Reset");

或设置自定义值:

Sitecore.Context.User.Profile.SetCustomProperty("Has Password Reset", "1");

配置文件本身应该位于 /sitecore/templates/System/Security 节点下的某处。如果您想从 UI 编辑特定用户的自定义配置文件值,您可以从 Sitecore 执行此操作:用户管理器 -->(单击用户)--> 配置文件 选项卡 --> 其他属性(下)

更多阅读:

http://blog.horizontalintegration.com/2014/04/07/sitecore-custom-user-profile-properties/

https://www.markstiles.net/Blog/2013/09/05/Sitecore-Custom-User-Properties.aspx

https://briancaos.wordpress.com/2014/06/12/sitecore-users-custom-profile-properties/

您似乎在使用 Sitecore Intranet。我不是 100% 熟悉它的细节(主要是我的同事与那部分一起工作),但这应该是你要找的:

using Sitecore.Intranet.Profiles;
using Sitecore.Intranet.Profiles.Providers;
using Sitecore.Security.Accounts; 

// ------------------------------

var userName = User.Current.Name;
var account = Account.FromName(userName, AccountType.User);

var profileProvider = new UserProfileProvider(new Settings());
var profile = profileProvider.GetProfile(account.LocalName.ToLower());

var profileItem = profile.ProfileItem;

我没有对此进行测试,因为我手头没有解决方案,所以如果有什么地方不对,请告诉我。