【发布时间】:2013-10-24 08:21:26
【问题描述】:
我使用的是 SharePoint 2010,但我似乎无法让此代码在我们的生产环境中返回任何内容。服务器设置为基于声明的身份验证。
private string GetADName(string userID)
{
try
{
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
// define a "query-by-example" principal - here, we search for a UserPrincipal
// and with the first name (GivenName) of "Bruce" and a last name (Surname) of "Miller"
UserPrincipal qbeUser = new UserPrincipal(ctx);
qbeUser.SamAccountName = userID;
// create your principal searcher passing in the QBE principal
PrincipalSearcher srch = new PrincipalSearcher(qbeUser);
// find all matches
foreach (var found in srch.FindAll())
{
return found.Name;
}
}
catch (Exception ex)
{
this.lblErrors.Text = ex.Message + "<br />\r\n" + ex.StackTrace;
}
return "";
}
【问题讨论】:
-
这段代码是否在您的暂存环境中工作?如果你传入“*”而不是用户 ID,你会得到结果吗?
标签: c# sharepoint-2010 active-directory