如何将用户从另一个域添加到本地域组?
使用C#我想将一个从一个域的用户添加到本地域。这些域具有两种信任。目前我有错误
'未找到与指定参数匹配的主体。”在.save()线上。
我有用户的dn(例如cn = adams,sam,ou = beer,dc = drainers,dc = local')。
这些组类似于CN =醉酒,OU =组,dc = bars,dc = local。
当它是相同的域时,这起作用了,但是当它是跨域时,就是当我获得错误时。我正在使用的用户帐户在本地具有管理权,并在其他域中读取权利。
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, m_AD_connection.Domain, m_AD_connection.Path, ContextOptions.Negotiate, m_AD_connection.UserName, m_AD_connection.Password))
{
GroupPrincipal group = GroupPrincipal.FindByIdentity(pc, GroupName);
if (group != null)
{
group.Members.Add(pc, IdentityType.DistinguishedName, DN);
group.Save();
return true;
}
else
return false;
}
关于我需要做的什么建议?
Using C# I would like to add a user from one domain to a local domain. The domains have a two way trust. Currently I get the error
'No principal matching the specified parameters was found.' on the .Save() line.
I have the DN of the user (e.g 'CN=Adams, Sam,OU=Beer, DC=Drinkers,DC=local').
The groups is something like CN=Drunks, OU=Groups,DC=Bars,DC=local.
This works when it is the same domain, but when it is cross domains is when I get the error. The user account that I am using has admin rights locally and read rights in the other domain.
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, m_AD_connection.Domain, m_AD_connection.Path, ContextOptions.Negotiate, m_AD_connection.UserName, m_AD_connection.Password))
{
GroupPrincipal group = GroupPrincipal.FindByIdentity(pc, GroupName);
if (group != null)
{
group.Members.Add(pc, IdentityType.DistinguishedName, DN);
group.Save();
return true;
}
else
return false;
}
Any suggestions on what I need to do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题在此行中:
上下文
参数应该是查找用户而不是组所需的上下文。因此,您需要为第二个域创建一个新的principalContext
,然后将其传递给add()
。例如:Your issue is in this line:
The
context
parameter should be the context required to look up the user, not the group. So you need to create a newPrincipalContext
for the second domain and pass that toAdd()
. For example: