2011-08-10 58 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))

相關問題