【问题标题】:Error while updating pictureurl property of Sharepoint userprofile更新 Sharepoint 用户配置文件的图片 URL 属性时出错
【发布时间】:2016-02-01 17:26:43
【问题描述】:

版本:SharePoint 2013

我正在尝试为 WCF 服务中的用户设置 pictureurl 属性。遵循的主要逻辑如本博客中提到的http://pholpar.wordpress.com/2010/03/10/how-to-upload-a-user-profile-photo-programmatically/

userProfile["PictureUrl"].Value = pictureUrl;

在这一行中,我收到异常“无法对正在访问的网站进行身份验证。”

感谢任何帮助。

【问题讨论】:

    标签: wcf sharepoint sharepoint-2013


    【解决方案1】:

    我在尝试更新用户配置文件属性时遇到了同样的错误,该代码对我有用:

    SPUserToken token = SPUserToken.SystemAccount;
    SPSecurity.RunWithElevatedPrivileges(delegate()
    {
        using (SPSite site = new SPSite(currGuid, token))
        {
            site.AllowUnsafeUpdates = true;
            HttpContext.Current = null; //clear the context for impersonation with token! mandatory!
            SPServiceContext serviceContext = SPServiceContext.GetContext(site);
            UserProfileManager profileManager = new UserProfileManager(serviceContext);
    
            UserProfile prof = profileManager.GetUserProfile(userName);
            prof["My Property"].Value = "abcd";
        }
    });
    

    修复错误的部分是在获取配置文件管理器之前清除当前上下文。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-21
      • 2017-10-06
      • 1970-01-01
      相关资源
      最近更新 更多