我有一个使用用户主体名称(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帐户转换为索赔,如果有的话,是否有人有关于如何做到这一点的示例?
答案 0 :(得分: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循环中,您可以检查您的字段并获取特定的用户详细信息
答案 1 :(得分:0)
在某些情况下,在具有联合身份验证的SharePoint网站下,在您未设置同步之前,不会自动创建用户配置文件。对于此问题,您可以通过中央管理员检查是否已存在jdoe@domain.globalx.com的用户个人资料。
此外,您的代码必须在模拟下运行,检查日志中的异常并尝试使用SPSecurity.RunWithElevatedPrivileges。