【问题标题】:SharePoint UserProfile from User Principal Name in Claims environment声明环境中用户主体名称的 SharePoint UserProfile
【发布时间】:2012-02-15 19:32:48
【问题描述】:

我有一个使用用户主体名称 (UPN) 格式保存在数据库中的帐户:jdoe@domain.gobalx.com

我正在使用 UPN 格式对声明进行身份验证的 SharePoint 环境中工作。

我的问题是我需要为持久化的 UPN 帐户获取一个 UserProfile 对象。我尝试了以下方法,但它不起作用:

string upnAccount = "jdoe@domain.globalx.com";
SPServiceContext ctx = SPServiceContext.GetContext(SPContext.Current.Site);
UserProfileManager upm = new UserProfileManager(ctx);
UserProfile user = upm.GetUserProfile(upnAccount);

我不断收到:Microsoft.Office.Server.UserProfiles.UserNotFoundException:检索用户配置文件时遇到错误

这是否意味着我必须将 UPN 帐户转换为索赔,如果是这样,有人有如何做到这一点的示例吗?

【问题讨论】:

    标签: sharepoint user-profile claims upn


    【解决方案1】:
                UserProfileManager UPM = null;
    
                using (SPSite site = new SPSite(SPContext.Current.Web.Url))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        ServerContext serverContext = ServerContext.GetContext(site);
                        UPM = new UserProfileManager(serverContext);
                         foreach (UserProfile profile in UPM)
                        {
    
                            an = profile["AccountName"].Value;
                            title = profile["Title"].Value;
                        }
                    }
                }
    

    你可以试试这个来获取所有用户配置文件。在 foreach 循环中,您可以检查您的字段并获取特定的用户详细信息

    【讨论】:

      【解决方案2】:

      在某些情况下,在具有联合身份验证的 SharePoint 网站下,在您未设置同步之前不会自动创建用户配置文件。对于这个问题,您可以通过 Central Admin 检查是否已经存在 jdoe@domain.globalx.com 的用户配置文件。

      此外,您的代码必须在模拟下运行,检查日志是否有异常并尝试使用 SPSecurity.RunWithElevatedPrivileges。

      【讨论】:

        猜你喜欢
        • 2018-06-04
        • 2020-02-20
        • 2015-10-20
        • 1970-01-01
        • 2021-11-08
        • 2017-06-24
        • 2019-08-08
        • 2016-09-06
        • 1970-01-01
        相关资源
        最近更新 更多