2011-08-10 282 views
1

我有一个SharePoint 2010事件接收器,需要更新站点上另一用户的用户配置文件,即不是触发该事件的用户。我尝试使用User Profile Admin的用户令牌打开UserProfileManager(如another question中建议的那样),但由于某些原因,它仍在触发事件的人的帐户下运行。
模仿用户配置文件服务应用程序管理员的正确方法是什么?因此我可以编辑任何用户的配置文件?管理SP2010用户配置文件作为用户配置文件管理员

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是可以接受的。

回答

0

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

相关问题