我正在使用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