我有一个SharePoint 2010事件接收器,需要更新网站上的另一个用户的用户配置文件,即不是触发事件的用户。我尝试使用用户配置文件管理员的用户令牌(如another question中所建议的)打开UserProfileManager,但由于某些原因,它仍然在触发事件的人的帐户下运行。
模拟User profile Service应用程序管理员以便我可以编辑任何用户的配置文件的正确方法是什么?
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而将应用程序池帐户添加到用户配置文件管理员是不可接受的。
发布于 2013-07-27 04:18:03
您是否尝试过使用系统帐户令牌(SPUserToken.SystemAccount)?使用(SPSite mySiteSite =新SPSite(mySiteHostUrl,SPUserToken.SystemAccount))
https://stackoverflow.com/questions/7018094
复制相似问题