[英]Getting “The server could not be contacted.” when trying to access active directory
I'm trying this code: 我正在尝试这段代码:
public bool isTravelAdmin(string srvr, string usr, string password)
{
System.Diagnostics.Debug.WriteLine("I'm in isTravelAdmin!");
PrincipalContext domainctx = new PrincipalContext(ContextType.Domain, srvr);
UserPrincipal userPrincipal = UserPrincipal.FindByIdentity(domainctx, IdentityType.SamAccountName, usr);
bool isMember = userPrincipal.IsMemberOf(domainctx, IdentityType.Name, "traveladmin");
if (isMember)
{
System.Diagnostics.Debug.WriteLine("This user is INDEED a member of that group");
return true;
}
else
{
System.Diagnostics.Debug.WriteLine("This user is *NOT* member of that group");
return false;
}
}
Which is supposed to check if a user belongs to a certain group ("traveladmin"), but I'm getting 应该检查用户是否属于某个组(“traveladmin”),但我得到了
System.DirectoryServices.AccountManagement.PrincipalServerDownException System.DirectoryServices.AccountManagement.PrincipalServerDownException
Any idea why and how to solve? 知道为什么以及如何解决? by the way: 顺便说说:
srvr = "LDAP://192.168.56.101/CN=Users,DC=estagioit,DC=local"
PS: I'm using the same srvr on another method and it's working and connecting. PS:我在另一种方法上使用相同的srvr,它正在工作和连接。
PSS: If this is not the best way to go about this I'm open to suggestions. PSS:如果这不是最好的解决方法,我愿意接受建议。
The problem is how the "Principal Context" is written... it should be: 问题是如何编写“主要上下文”......它应该是:
PrincipalContext thisPrincipalContext = new PrincipalContext(ContextType.Domain, "DCESTAGIO");
in this case. 在这种情况下。
If you look at the documentation for the PrincipalContext
constructors, it should be quite clear: 如果查看PrincipalContext
构造函数的文档,应该非常清楚:
public PrincipalContext(ContextType contextType, string name)
or 要么
public PrincipalContext(ContextType contextType, string name, string container)
So you basically need: 所以你基本上需要:
ContextType.Domain
) 你的上下文类型(这里: ContextType.Domain
) LDAP://
prefix) 可选的容器(作为LDAP路径 - “区分”名称,完整路径但没有任何LDAP://
前缀) 在您的情况下,只需将您的srvr
更改为:
srvr = "DCESTAGIO"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.