检索用户配置文件时遇到错误

时间:2012-03-06 05:41:45

标签: sharepoint user-profile

我在尝试检索用户个人资料时遇到此错误:

An error was encountered while retrieving the user profile.

这是我的代码:

foreach (SPUser parent in parentGroup.Users)
{
    SPSecurity.RunWithElevatedPrivileges(delegate()
    {
        using (SPSite elevatedSite = new SPSite(site.ID))
        {
            using (SPWeb elevatedWeb = site.OpenWeb(web.ID))
            {
                elevatedWeb.EnsureUser(parent.LoginName);
            }
        }
    });
    web.EnsureUser(parent.LoginName);
    try
    {
        UserProfile profile = upm.GetUserProfile(parent.LoginName);
        if ((bool)profile["ParentAssignmentSubscribe"].Value)
        {
            receivingParents.Add(new SlkUser(parent));
        }
    }
    catch(Exception ex)
    {
        throw new Exception("failed to load profile of " + parent.LoginName + " in order to send them an assignment notification for web " + web.Name + ". The error returned was: " + ex.Message);
    }
}

显然用户确实存在,因为我从组中获取了他的用户名,而且我也在使用EnsureUser。发生了什么事?

2 个答案:

答案 0 :(得分:0)

也许是因为您的流程无法找到您的用户个人资料。

您可以尝试以下步骤吗?

  1. 打开中央管理员 - →安全性 - →常规安全性,从配置服务帐户复制用户名

  2. 打开中央管理员 - →应用程序管理→服务应用程序→管理服务应用程序。

  3. 从您在步骤2中打开的页面中单击用户配置文件服务,然后选择从人员管理用户配置文件

  4. 您可以按步骤1中复制的用户名搜索用户个人资料,如果找不到,可能是您的错误原因。

  5. 点击新建个人资料,为您的用户名创建新的个人资料(在步骤1)。

答案 1 :(得分:0)

user = profileManager.GetUserProfile(_userName) 

应改为:

user = profileManager.GetUserProfile(@"domain name\username");