0

次のコードでユーザー プロファイル プロパティを変更しようとしています

SPSecurity.RunWithElevatedPrivileges(delegate(){
SPSite currentSite = new SPSite(SPContext.Current.Web.Url);

SPServiceContext serviceContext = SPServiceContext.GetContext(currentSite);
UserProfileManager upm = new UserProfileManager(serviceContext);
UserProfile up1 = upm.GetUserProfile("DOMAIN\\User3");
up1["CustomProperty"].Value=10;           
up1.Commit();

currentSite.Dispose();
});

そして、すべてのユーザープロファイルを変更する権限を持つアカウント User1 でページを開くと、問題ありません。しかし、User2 (権限なし) でページを開くと、403 エラーが発生します。デバッガーで up1["CustomProperty"].Value が null です。

SPSecurity.RunWithElevatedPrivileges が効果がない理由と、この問題を解決するにはどうすればよいですか?

ありがとう

4

1 に答える 1

0

次の記事で私の問題の説明を見つけました Impersonation not work with UserProfileManager

その理由として、ユーザー プロファイル プロパティを取得または設定するたびに HttpContext をクリアできます。たとえば、次のコードはうまく機能します。

 SPSecurity.RunWithElevatedPrivileges(delegate()
        {
            HttpContext tempCtx = HttpContext.Current;
            HttpContext.Current = null;

            UserProfile userProfile = GetUserProfile(user);
            userProfile["SomeProperty"].Value = points;
            userProfile.Commit();

            HttpContext.Current = tempCtx;
        });
于 2015-08-17T13:43:05.693 に答える