【问题标题】:Authenticate against Active Dir on remote machine using C#使用 C# 对远程计算机上的 Active Dir 进行身份验证
【发布时间】:2012-10-25 11:49:04
【问题描述】:

如何访问远程机器上的 Active Directory。 我在 Azure 中创建了一个安装了 AD 的 win server 2008 R2。主机名:MyVMachine,DNS:myapp.cloudapp.net。我可以通过笔记本电脑使用远程桌面连接访问机器。

我想针对该 AD 对用户进行身份验证。我应该使用 ContextType.Domain 还是 ContextType.Machine 以及 LDAP,如何构建它以联系该 AD?此代码位于我笔记本电脑的 WCF 服务应用程序中。以下方法不起作用:

        using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, "LDAP://MyVMachine.testenv.local/ou=Users,dc=testenv,dc=local"))
        {
            // validate the credentials
            bool b = pc.ValidateCredentials("Administrator", "password");
            return true;
        }

我想在这里验证用户管理员,我看到存在于 testenv.local 节点 i AD 机器的用户节点中。

使用此代码,我得到“无法联系服务器”。与 principalServerDownExceptioan。

我需要帮助。

谢谢大家

我在 Azure 中的 AD 机器:

【问题讨论】:

    标签: authentication azure active-directory


    【解决方案1】:

    您当前请求的方案是不可能的,也不支持。到今天为止,唯一受支持的选项(它仍处于 PREVIEW 中)是 Azure 中的 Active Directory REPLICA。这意味着您必须拥有本地 AD 并将 Azure 用作副本。

    为了复制副本,您必须配置Azure Virtual Network 以在本地计算机和 Windows Azure 虚拟网络之间建立 VPN。

    我的猜测和推测

    其中一个可能的原因(我的猜测)是,目前在 Windows Azure 虚拟网络中,虽然您自己定义了子网,但所有 VM 必须具有 DHCP 分配的 IP 地址。而主域控制器必须具有静态 IP 地址。

    更新

    如果您只想使用LDAP://MyVMachine.testenv.local/ 中描述的 LDAP 功能,您必须在 Windows Server Firewll 和 Windows Azure 虚拟机输入端点中打开 LDAP 端口(可从新门户配置,当您在那里选择 VM 时)是顶部的“端点”菜单项)。应该是TCP protocol on (default) port 389 or 636 for SSL。并且您还必须安装服务器的 LDAP 功能并对其进行配置。但这些是更多 AD/LDAP 细节,如果你不知道最好在 serverfault 上询问。

    【讨论】: