c# - Active Directory 不适用于异地

标签 c# active-directory

使用的技术:asp.net(C#)、MVC、LINQ、Entity

我在公司网站上使用 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 默认执行的操作吗?

最佳答案

与 AD 的连接将始终需要 Windows 凭据。您发布的代码不向 AD 提供任何凭据。 (您传入要查找的用户名,但这与提供连接凭据不同)。这将适用于其计算机附加到域的用户......因为您的网络凭据是隐式传递的。对于外部开发人员,当他们进入 VPN 时,他们会向 VPN 协议(protocol)提供凭据,这允许他们的机器访问您的网络,但这并不意味着他们的机器已“加入”域......因此 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 标志。

关于c# - Active Directory 不适用于异地,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18385288/

相关文章:

asp.net - IIS 应用程序池不会在组托管服务帐户下启动

c# - Graph API 从 Azure AD 获取用户

PowerShell Active Directory 列出所有多值属性

c# - 当 SQL Azure 中不存在数据库时,是否需要先迁移 EF 代码?

c# - JavaScriptSerializer 可以排除具有空值/默认值的属性吗?

c# - 在 Visual Studio 中调试时向后拖动指令指针

c# - 如果应用服务器在 Active Directory A 中,如何查询 Active Directory B

c# - winmm.dll mciSendString 可能的最低音频设置?

媒体文件元数据的 C# 包装器

powershell - Get-ADUser 整个林