以用户配置文件管理员身份管理SP2010用户配置文件

本文关键字:配置文件 用户 SP2010 管理 管理员 身份 | 更新日期: 2023-09-27 18:05:15

我有一个SharePoint 2010事件接收器,需要更新站点上另一个用户的用户配置文件,即不是触发事件的用户。我尝试使用user Profile Admin的用户令牌打开UserProfileManager(如另一个问题所建议的),但由于某种原因,它仍然在触发事件的人的帐户下运行。
冒充用户配置文件服务应用程序管理员以便编辑任何用户的配置文件的正确方法是什么?

SPUserToken upmToken = web.AllUsers[@"domain'upadmin"].UserToken;//this user is a User Profile Service Application Administrator
using (SPSite upmSite = new SPSite(web.Url, upmToken))
{
    SPServiceContext context = SPServiceContext.GetContext(upmSite);
    UserProfileManager userProfileManager = new UserProfileManager(context, false);
    UserProfile userProfile = userProfileManager.GetUserProfile("anotheruser");
    userProfile["PictureUrl"].Value = pictureUrl;//System.UnauthorizedAccessException: Attempted to perform an unauthorized operation
    userProfile.Commit();
}

如果我将自己添加到用户配置文件服务应用程序管理员中,代码运行良好,因此它显然仍然试图在触发事件接收器的用户的帐户下打开UserProfileManager。
我不认为为了使用RunWithElevatedPermissions而将应用程序池帐户添加到用户配置文件管理员中是可以接受的。

以用户配置文件管理员身份管理SP2010用户配置文件

您是否尝试过使用系统帐户令牌(SPUserToken.SystemAccount)?using (SPSite mysiteesite = new SPSite(mySiteHostUrl, SPUserToken.SystemAccount))