使用的技术: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/