【问题标题】:Update sharepoint user profile property with SPSecurity.RunWithElevatedPrivileges使用 SPSecurity.RunWithElevatedPrivileges 更新共享点用户配置文件属性
【发布时间】:2015-08-17 09:55:16
【问题描述】:

我尝试使用下一个代码更改用户配置文件属性

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 为空。

为什么 SPSecurity.RunWithElevatedPrivileges 没有效果,我该如何解决这个问题?

谢谢

【问题讨论】:

    标签: sharepoint impersonation sharepoint-userprofile


    【解决方案1】:

    我在下一篇文章中找到了我的问题的描述 Impersonation does 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;
            });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-26
      相关资源
      最近更新 更多