我正在使用LDAP,我对此很陌生。LDAP路径问题
有没有办法获得理想的域名时,你只知道用户名,密码,服务器名
我试图做到这一点:
string ldapPath = "LDAP://serverName";
string uid = username;
string password = pwd;
string qry = String.Format("(uid={0})", uid);
string adsPath = String.Empty;
try
{
DirectoryEntry nRoot = new DirectoryEntry(ldapPath, null, null, AuthenticationTypes.Anonymous);
DirectorySearcher ds = new DirectorySearcher(nRoot, qry);
SearchResult sr = ds.FindOne();
if (sr != null)
{
// we want to retrieve the DN like this: "uid=myuser,ou=People,dc=findlay,dc=edu
ldapPath = sr.Path; //update where we will bind next
}
这并不工作,除非我改变
string ldapPath = "LDAP://serverName";
到
string ldapPath = "LDAP://serverName/DC=mydomain,DC=com";
任何帮助.. ??
感谢
编辑RootDSE的
string defaultNamingContext;
using (DirectoryEntry rootDSE = new DirectoryEntry("LDAP://serverName/rootDSE", null, null, AuthenticationTypes.Anonymous))
{
defaultNamingContext = rootDSE.Properties["rootDomainNamingContext"].Value.ToString();
}
我也觉得这是解决方案,但目前没有工作对我来说..请帮助!
可能重复[从LDAP目录上下文对象查找BASE DN](http://stackoverflow.com/questions/7777067/find-base-dn-from-ldap-directory-context-object) – EJP
它是不均匀的标记为已回答..请改为帮忙。谢谢 – user175084
但它*是*回答了两次。 – EJP