2014-03-04 55 views
2

我知道这个问题之前已经被问过了,我为打开另一个问题而道歉,但是我在线阅读的所有解决方案都没有解决我遇到的问题。出于最好不说的原因,我需要在接下来的三天内完成这项工作。我以前只使用过LDAP,并且我没有人可以帮助我(甚至不是管理员)。无法连接到LDAP“无效的DN语法”

这是我想要的基本代码:

DirectoryEntry rootEntry = new DirectoryEntry("LDAP://serverName.dev.domain.com:portNumber/o-domain,o=dxc.com","uid=userName,ou=bindids,o=domain,o=dcx.com", "password", AuthenticationTypes.None); 
DirectorySearcher dSearch = new DirectorySearcher(rootEntry); 
try 
{ 
foreach (SearchResult result in dSearch.FindAll()) 

等。这失败的dSearch.FindAll()行

我没有查询在这个时候写的(建议/语法上这将是AWESEOME),因为我不知道我需要从目录中拉回什么值。管理员告诉我这不是活动目录。

当我删除AuthenticationTypes时,出现不同的错误,说我有一个未知的用户名或密码错误。我的管理员已经检查并确保他们工作。他甚至重置了密码,以防止它是一个保留的字符问题。

任何帮助或想法,你可以提供将不胜感激。我一直在这里工作了大约12个小时,我的大脑被打乱了。

编辑:以下是完整的错误

Error: An invalid dn Syntax has been specified

@Alexanderius - 谢谢你的另一种格式。有了这个,我得到一个COMException:服务器不是Operational。

@ X3074861X - 这是一个Oracle Directory Server(又名SUN One Directory Server)。

编辑:我稍微修改了我的代码。 (将o域更改为o =域并添加了不同的查询)。现在我得到一个COMException:“服务器上没有这样的对象”。

DirectoryEntry rootEntry = new DirectoryEntry("LDAP://ServerName.Domain.com:2394/o=Domanin,o=dxc.com", 
        "uid=UserName,ou=bindids,o=Domain,o=dcx.com", "Password", AuthenticationTypes.None); 
DirectorySearcher dSearch = new DirectorySearcher(rootEntry); 
dSearch.Filter = "uid=" + "AUser"; 
dSearch.SizeLimit = 100; 
dSearch.SearchScope = SearchScope.Subtree; 
try 
{ 
SearchResult newTest = dSearch.FindOne(); 

等等。

更新:还有一个错误,我没有通知!在绑定语句之后,当我将鼠标悬停在“rootEntry”上时,我发现它有一个'System.Runtime.InteropServices.COMException:未指定的错误\ r \ n“。这对我没有什么帮助,但也许你们中的一个人见过?前

+0

你能发表详细的错误? –

+0

你知道这是什么类型的目录吗? Novell公司? Lotus Domino?的iPlanet? – X3074861X

回答

1

我连接到我的广告是这样的:

DirectoryEntry = new DirectoryEntry("LDAP://Myserver/MyRootEntry,dc=MyDomainName,dc=net", "SomeUserName", "SomeUserPassword", AuthenticationTypes.Secure); 

我的服务器名是:myserver.mydomain.net

尝试连接这样的

0

我。我一直在使用这个实现来验证通过使用SUN堆栈构建的iPlanet来验证用户,因此它也应该可以在Oracle Directory服务器上运行。对于定制和一些较低级别细节的,我是System.DirectoryServicesSystem.DirectoryServices.Protocols库的超级粉丝,特别是与非AD目录服务器工作时:

// build your server name - we'll use 'serverName.dev.domain.com' and port 389 
var BuildServerName = new StringBuilder(); 
BuildServerName.Append("serverName.dev.domain.com"); 
BuildServerName.Append(":" + Convert.ToString(389)); 

// setup an ldapconnection to that endpoint 
var ldapConnection = new LdapConnection(BuildServerName.ToString()); 

现在,我们需要详细了解这方面的一些信息:

// it looks like you have an administrative account to bind with, so use that here 
var networkCredential = new NetworkCredential("userName", "password", "dc=MyDomainName,dc=net"); 

// set the following to true if it's over ssl (636), if not just set it to false 
ldapConnection.SessionOptions.SecureSocketLayer = SSL; 
ldapConnection.SessionOptions.VerifyServerCertificate += delegate { return true; }; 

// now set your auth type - I typically use 'negotiate' over LDAPS, and `simple` over LDAP 
// for this example we'll just say you're not using LDAPS 
ldapConnection.AuthType = AuthType.Basic; 
ldapConnection.Bind(networkCredential); 

现在你应该绑定到该目录,这意味着你可以使用SearchRequest对象搜索。以下是我如何使用它的一个示例:

// setup a new search request 
var findThem = new SearchRequest(); 
findThem.Filter = "This is where you need to construct a filter for what you're looking for" 
findThem.Scope = System.DirectoryServices.Protocols.SearchScope.Subtree; 

// we'll execute a search using the binded administrative user 
var searchresults = (SearchResponse) ldapConnection.SendRequest(findThem); 

// this will contain entries if your search filter returned any results 
if(searchresults.Entries.Count >= 1) 
{ 
    // here are your list of returned entries 
    SearchResultEntryCollection entries = searchresults.Entries; 

    // do some work\extraction on them 
} 

这里的最后一部分是您的实际LDAP过滤器。如果您想您的域名中搜索与userName一个uid用户,您的过滤器应为:

findthem.Filter = "(uid=username)"; 

如果你想结合说具有特定属性的objectClass,你会怎么做:

findthem.Filter = "(&(objectClass=user)(uid=username))"; 

这里是在过滤了一些很好的联系:

LDAP Filtering Syntax

LDAP Query Basics

Oracle LDAP Search Filters