Active Directory不适用于异地

时间:2013-08-22 15:50:31

标签: c# active-directory

使用的技术:asp.net(C#),MVC,LINQ,实体

我在公司网站上使用Active Directory。该系统适用于现场所有员工,当我们将笔记本电脑放在异地并使用VPN时。

但是我们最近聘请了一些我们已经提供VPN访问权限的开发人员(异地)。但他们无法运行我们的代码,我不确定为什么。我们为他们设置了活动目录用户,他们可以通过VPN连接到我们。

他们遇到了两个错误。

用户名/密码错误。
服务器不是操作错误。

VPN用户名/密码是否必须与活动目录帐户匹配? 如果他们登录到他们的开发机器,那么用户名/密码必须与活动目录帐户匹配吗?

Active Directory和非现场是否有一些限制我不知道为什么这对我们有效,但对我们的非现场开发人员不起作用?

以下是给出错误的代码部分:行SearchResult rs = ds.FindOne();

上的错误
public AD_CurrentUserProfile GetUserProfile(string userName)
        {
            using (DirectoryEntry de = new DirectoryEntry("LDAP://server.com"))
            using (DirectorySearcher ds = new DirectorySearcher(de))
            {
                ds.SearchScope = SearchScope.Subtree;

                ds.Filter = ("(&(objectCategory=person)(objectClass=User)(samaccountname=" + userName + "))");
                ds.PropertiesToLoad.Add("distinguishedName");
                ds.PropertiesToLoad.Add("manager");
                ds.PropertiesToLoad.Add("directreports");

                SearchResult rs = ds.FindOne();

                AD_CurrentUserProfile userProfile = new AD_CurrentUserProfile();

                userProfile.currentUser = GetProfileFromDN(rs.Properties["distinguishedName"][0].ToString());
                userProfile.managerProfile = GetProfileFromDN(rs.Properties["manager"][0].ToString(), true);

                int departmentID = db.IPACS_Department.First(v => (v.name == userProfile.currentUser.department)).departmentID;
                userProfile.ipacs_department = db.IPACS_Department.Find(departmentID);

                if (userProfile.currentUser.userName == userProfile.ipacs_department.owner)
                {
                    userProfile.currentUser.isManager = true;
                }

                // Override for Provana and upper management
                if (userProfile.currentUser.department == "Provana" || userProfile.currentUser.department == "JM")
                {
                    userProfile.currentUser.isManager = true;
                }

                if (rs.Properties["DirectReports"].Count > 0)
                {
                    if (!userProfile.currentUser.isManager)
                    {
                        userProfile.currentUser.isSupervisor = true;
                    }
                    userProfile.directReports = new HashSet<AD_User>();

                    foreach (string value in rs.Properties["DirectReports"])
                    {
                        userProfile.directReports.Add(GetProfileFromDN(value));
                    }
                }

                return userProfile;
            }
        }

我从未在任何代码中的任何地方传递'密码',因此默认情况下Active Directory会执行此操作吗?

1 个答案:

答案 0 :(得分:1)

与AD的连接始终需要Windows凭据。您发布的代码不会向AD提供任何凭据。 (您传入的是您正在查找的用户名,但这与为连接提供凭据不同)。这适用于其计算机连接到域的用户...因为您的网络凭据是隐式传递的。对于外部开发人员,当他们进入VPN时,他们会为VPN协议提供凭据,这允许他们的计算机访问您的网络,但这并不意味着他们的计算机已经加入了#到域名...所以AD仍然需要来自他们的显式凭据,包括个人密码或有权访问AD的服务帐户密码。

这一行:

using (DirectoryEntry de = new DirectoryEntry("LDAP://server.com"))

基本上需要允许用户名和密码:

using (DirectoryEntry de = new DirectoryEntry("LDAP://server.com"), userName, pwd)
{
  de.AuthenticationType = AuthenticationTypes.None | AuthenticationTypes.ReadonlyServer;
}

...您必须尝试使用​​AuthenticationTypes标志,具体取决于您的网络管理员如何设置它。