尝试解析跨商店引用时,无法解析目标主体的SID.错误代码为1332 [英] While trying to resolve a cross-store reference, the SID of the target principal could not be resolved. The error code is 1332
问题描述
从组中获取用户时,异常消息为尝试解析跨存储引用时,无法解析目标主体的SID.错误代码为1332."
While fetching users from group, giving exception message as "While trying to resolve a cross-store reference, the SID of the target principal could not be resolved. The error code is 1332."
PrincipalContext ctx = null;
if (!string.IsNullOrWhiteSpace(adUserName))
{
ctx = new PrincipalContext(ContextType.Domain, domainName, adUserName, adPassword);
}
else
{
ctx = new PrincipalContext(ContextType.Domain, domainName);
}
var groupNames = commaSeparatedGroupNames.Split(',');
IEnumerable<Principal> users = null;
foreach (var groupName in groupNames)
{
if (!string.IsNullOrWhiteSpace(groupName))
{
var userGroup = GroupPrincipal.FindByIdentity(ctx, groupName.Trim());
if (userGroup == null)
throw new InvalidOperationException("Active Directory Group Not Found :: " + groupName);
var usersInGroup = userGroup.GetMembers();
if (users == null)
{
users = usersInGroup;
}
else
{
users = users.Union(usersInGroup);
}
}
}
return users;
这样做的时候
foreach (UserPrincipal user in users)
我得到了错误. 在循环过程中,我可以检查此错误或从列表中跳过此成员的任何建议.
I am getting the error. Any suggestions i can check for this error or skip this member from list during looping.
推荐答案
I just encountered this same problem yesterday, and this is the best answer I found at this link:
IEnumerator<Principal> enumerator = members.GetEnumerator();
while (enumerator.MoveNext())
{
try
{
Principal member = enumerator.Current;
Console.WriteLine({0}\r\n\t{1}\r\n\t{2}",member.ToString(),member.Guid,member.DistinguishedName);
} catch (Exception ex) {
Console.WriteLine(ex.Message);
}
}
这是您将手动"迭代IEnumerable集合的方式.如果是未定义的SID或其他问题,它使您有机会尝试获取Principal并捕获异常.
This is how you would iterate the IEnumerable collection 'manually'. It gives you a chance to attempt getting the Principal and to catch the exception if it's an undefined SID or some other issue.
这篇关于尝试解析跨商店引用时,无法解析目标主体的SID.错误代码为1332的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!