声明环境中用户主体名称中的SharePoint UserProfile



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

我在一个SharePoint环境中工作,该环境使用UPN格式对声明进行身份验证。

我的问题是,我需要为持久化的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帐户转换为索赔,如果是,有人有如何做到这一点的例子吗?

            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循环中,你可以检查你的字段并获得相关的用户详细信息

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

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

最新更新