我正在运行域DOMAIN1中的代码。使用DOMAIN2设置单向信任。我希望验证DOMAIN2中的用户是否存在。当我尝试时,我得到一个例外,说“用户名和密码无效”。我认为我必须向DOMAIN2中存在的用户提供凭据以允许搜索,但我该怎么做?以及如何修复它以便不需要身份验证(双向信任?)
try
{
//this works find for a user in the current domain
PrincipalContext ctx1 = new PrincipalContext(ContextType.Domain, "DOMAIN1");
UserPrincipal user1 = UserPrincipal.FindByIdentity(ctx1, "user1");
GroupPrincipal group1 = GroupPrincipal.FindByIdentity(ctx1, "group1");
bool ue1 = user1.IsMemberOf(group1);
//this fails with invalid username/password but is a trusted domain
PrincipalContext ctx2 = new PrincipalContext(ContextType.Domain, "DOMAIN2");
UserPrincipal user2 = UserPrincipal.FindByIdentity(ctx2, "user2");
GroupPrincipal group2 = GroupPrincipal.FindByIdentity(ctx2, "group2");
bool ue2 = user2.IsMemberOf(group2);
}
catch (Exception e)
{
string ex;
ex = e.Message;
}
答案 0 :(得分:0)
使用接受用户名和密码的PrincipalContext constructor。
PrincipalContext ctx1 = new PrincipalContext(ContextType.Domain, "DOMAIN1", "username", "password");
如果您不想传递凭据,那么您的应用程序需要在两个域都信任的凭据下运行。
因此,如果DOMAIN1信任DOMAIN2,那么您的应用程序应该在DOMAIN2上的凭据下运行。
如果DOMAIN2信任DOMAIN1,那么您的应用程序应该在DOMAIN1上的凭据下运行。
如果你不能那样做,那么,是的,双向信任会解决它。