2011-08-10 15 views
1

私は、サイト上の別のユーザーのユーザープロファイルを更新する必要があるSharePoint 2010イベント受信者を用意しています。ユーザープロファイル管理者のユーザートークン(another questionのように)でUserProfileManagerを開こうとしましたが、何らかの理由でイベントを発生させた人のアカウントでまだ実行されています。
User Profile Serviceアプリケーション管理者を偽装してユーザーのプロファイルを編集できる正しい方法は何ですか?ユーザープロファイル管理者として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(); 
} 

私は、User Profile Serviceアプリケーションの管理者に自分自身を追加した場合、明らかにまだイベントの受信をトリガしたユーザーのアカウントでUserProfileManagerにを開こうとしているので、コードは正常に動作します。
RunWithElevatedPermissionsを使用するために、ユーザープール管理者にアプリケーションプールアカウントを追加することは容認できません。

答えて

0

システムアカウントトークン(SPUserToken.SystemAccount)を試したことがありますか? using(SPSite mySiteSite =新しいSPSite(mySiteHostUrl、SPUserToken.SystemAccount))

関連する問題