C# 作为用户配置文件管理员管理SP2010用户配置文件

C# 作为用户配置文件管理员管理SP2010用户配置文件,c#,sharepoint,sharepoint-2010,C#,Sharepoint,Sharepoint 2010,我有一个SharePoint 2010事件接收器,需要更新网站上另一个用户的用户配置文件,即不是触发事件的用户。我尝试使用中建议的用户配置文件管理员的用户令牌打开UserProfileManager,但由于某些原因,它仍在触发事件的人的帐户下运行。 模拟用户配置文件服务应用程序管理员以便编辑任何用户的配置文件的正确方法是什么 SPUserToken upmToken = web.AllUsers[@"domain\upadmin"].UserToken;//this user is a User

我有一个SharePoint 2010事件接收器,需要更新网站上另一个用户的用户配置文件,即不是触发事件的用户。我尝试使用中建议的用户配置文件管理员的用户令牌打开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();
}
如果我将自己添加到User Profile Service Application Administrators中,代码运行良好,因此显然它仍在尝试在触发事件接收器的用户的帐户下打开UserProfileManager。
我认为将应用程序池帐户添加到用户配置文件管理员以使用RunWithElevatedPermissions是不可接受的。

您是否尝试过使用系统帐户令牌SPUserToken.SystemAccount? 使用SPSite mysite=new SPSitemySiteHostUrl,SPUserToken.SystemAccount