从Active Directory检索组下的用户时出现错误。错误描述是 {“无法检索有关域的信息(1355)”}。尝试使用.Net 4.0和.Net 4.5。 我收到错误的行被注释错误消息。
public List<DirectoryUser> GetUsersUnderGroup(string groupName)
{
var directoryUserList = new List<DirectoryUser>();
string directoryServerIp="192.168.1.xxx";
string ouName="xxxOuName";
string domainComponents="DC=xxxComopnent1,DC=xxxComponent2";
string directoryAdminUserId="directoryAdminuser";
string directoryAdminPassword="directoryAdminPassword";
using (var principalContext = principalContext = new PrincipalContext(ContextType.Domain, directoryServerIp, string.Format("OU={0},{1}", ouName, domainComponents), directoryAdminUserId, directoryAdminPassword);)
{
using (var group = GroupPrincipal.FindByIdentity(principalContext, groupName))
{
if (group != null)
{
var users = group.GetMembers(true);
//Works fine till the above line. variable users is having not null value but
//exception while iterating through the loop.Following is the exception
//{"Information about the domain could not be retrieved (1355)."}
foreach(var user in users)
{
Console.Write(user.DistinguishedName);
}
}
}
}
return directoryUserList;
}
创建PrincipalContext的代码在其他方案中运行良好(例如获取组列表和OU等)