简体   繁体   English

尝试访问活动目录时出现“无法联系服务器。”

[英]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: 所以你基本上需要:

  • your context type (here: ContextType.Domain ) 你的上下文类型(这里: ContextType.Domain
  • the domain name (try just the "Netbios" name, eg "YOURDOMAIN" - or leave NULL for "default" domain) 域名(只需尝试“Netbios”名称,例如“YOURDOMAIN” - 或为“默认”域留下NULL)
  • optionally a container (as an LDAP path - a "distinguished" name, full path but without any LDAP:// prefix) 可选的容器(作为LDAP路径 - “区分”名称,完整路径但没有任何LDAP://前缀)

as seen in this answer. 正如这个答案所见。

在您的情况下,只需将您的srvr更改为:

srvr = "DCESTAGIO"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Active Directory:无法使用DirectorySearcher与服务器联系 - Active Directory: The server could not be contacted using DirectorySearcher “指定的域不存在或无法联系。” - “The specified domain either does not exist or could not be contacted.” 为什么不能通过PrincipalContext联系Active Directory服务器? - Why can't the Active Directory server be contacted via PrincipalContext? 尝试访问活动目录时出现DirectoryServicesCOMException(0x80072030) - DirectoryServicesCOMException (0x80072030) when trying to access active directory 尝试访问 Active Directory 中的属性以添加到数据库 - Trying to access Properties in Active Directory to add to a Database ActiveDirectoryMembershipProvider“更改为Comcast后,无法联系指定的域或服务器” - ActiveDirectoryMembershipProvider “The specified domain or server could not be contacted” AFTER changing to Comcast 仅在服务器上查询Active Directory时出错 - Getting Error Querying Active Directory On The Server Only 尝试访问用户信息时,尚未初始化Active Directory成员资格提供程序 - The Active Directory Membership Provider has not been initialized when trying to access user information System.DirectoryServices.AccountManagement.PrincipalServerDownException:无法联系服务器 - System.DirectoryServices.AccountManagement.PrincipalServerDownException: The server could not be contacted 尝试从 android 应用程序登录到我的服务器时出现“无法建立 ssl 连接”或“SSL 握手中止” - Getting "The ssl connection could not be established" or "SSL handshake aborted" when trying to log in from android app to my server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM