【发布时间】:2016-08-08 06:58:58
【问题描述】:
如何验证LDAP 路径?我有三个textboxes,允许用户输入 LDAP 路径、用户名和密码。我能够验证用户名和密码,但在验证 LDAP 路径时,它最初可以工作,但一段时间后,它也允许无效路径。
有效的 LDAP 路径:
192.168.12.12:565
LDAP 路径无效:
gfg192.168.12.12:565fgfgf
并且用户能够获取使用无效路径的用户列表。
我试过LdapConnection,使用Directory Entry和使用PrincipalContext:
LdapConnection connection = new LdapConnection(txtLDAPPath.Text.Trim());
NetworkCredential credential = new NetworkCredential(txtADUserName.Text.Trim(), password);
connection.Credential = credential;
connection.Bind();
using (DirectoryEntry entry = new DirectoryEntry())
{
entry.Username = txtADUserName.Text.Trim();
entry.Password = password;
entry.Path = txtLDAPPath.Text;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(&(objectClass=user)(objectCategory=person)(!userAccountControl:1.2.840.113556.1.4.803:=2))";
object obj = entry.NativeObject;
SearchResult resultCol = search.FindOne();
}
PrincipalContext ctx = new PrincipalContext(ContextType.Domain,"Domain");
bool Validate= ctx.ValidateCredentials(txtADUserName.Text, password);
【问题讨论】:
-
到目前为止你尝试过什么?你真的希望社区在不分享你的代码的情况下做什么?请参考How do I ask a good question?
-
我已经发布了我的代码@uteist 我尝试了提到的各种方法,但没有一个验证 LDAP 路径。
-
快速浏览一下,我可以看出您实际上根本没有使用
LdapConnection。您可能会发现 this link 对您的 AD 应用很有帮助。 -
我已经一一尝试了所有这些方法,但似乎没有人在验证 LDAP 路径。@uteist
-
我允许用户在文本框中输入 LDAP 路径并进行验证。@Burzum
标签: c# asp.net authentication active-directory