여기에 내가 AD 쿼리하는 데 사용하는 코드입니다 :
public class ADHelper
{
public static Employee getUserName(string loginName)
{
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
UserPrincipal principal = new UserPrincipal(ctx);
principal.SamAccountName = Regex.Replace(loginName, ".*\\\\(.*)", "$1", RegexOptions.None);
// create your principal searcher passing in the QBE principal
PrincipalSearcher srch = new PrincipalSearcher(principal);
// find all matches
Employee employee = new Employee();
foreach (var found in srch.FindAll())
{
UserPrincipal principal2 = (UserPrincipal)found;
//FirstName
employee.FirstName = principal2.GivenName;
//Middle Name
employee.MiddleName = principal2.MiddleName;
//LastName
employee.LastName = principal2.Surname;
}
return employee;
}
}
public class Employee
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string MiddleName { get; set; }
public string getFullName()
{
return LastName + ", " + FirstName + " " + MiddleName;
}
}
는 그리고 이것은 내가 셰어 포인트에서 호출하는 방법입니다
ADHelper.getUserName(SPContext.Current.Web.CurrentUser.LoginName);