2016-07-27 16 views
-1

c#を使用してLDAP接続を作成しようとしています。 .NETでのLDAP接続の作成

は私が多くの記事をGoogleで検索し、連結コード

string domain = "ldap://ldap.forumsys.com/ou=mathematicians"; 
      string username = "cn=read-only-admin,dc=example,dc=com"; 
      string password = "password"; 
      string LdapPath = "Ldap://ldap.forumsys.com:389/ou=scientists,dc=example,dc=com"; 


      string domainAndUsername = domain + @"\" + username; 
      DirectoryEntry entry = new DirectoryEntry(LdapPath, domainAndUsername, password); 
      try 
      { 
       // Bind to the native AdsObject to force authentication. 
       Object obj = entry.NativeObject; 
       DirectorySearcher search = new DirectorySearcher(entry); 
       search.Filter = "(SAMAccountName=" + username + ")"; 
       search.PropertiesToLoad.Add("cn"); 
       SearchResult result = search.FindOne(); 

       // Update the new path to the user in the directory 
       LdapPath = result.Path; 
       string _filterAttribute = (String)result.Properties["cn"][0]; 
      } 
      catch (Exception ex) 
      { 

       throw new Exception("Error authenticating user." + ex.Message); 
      } 
を作成しようとしました

http://www.forumsys.com/en/tutorials/integration-how-to/ldap/online-ldap-test-server/

をテストするために、LDAPサーバを提供します。このサーバーを見つけ

このコードは、それが与えている接続されていません予期せぬエラー..

私はまた、いくつかの他の資格情報を試してみましたが、どちらかを助けていない...

AUTH_LDAP_SERVER_URI = “ldap://ldap.forumsys.com” 
AUTH_LDAP_BIND_DN = “cn=read-only-admin,dc=example,dc=com” 
AUTH_LDAP_BIND_PASSWORD = “password” 
AUTH_LDAP_USER_SEARCH = LDAPSearch(“ou=mathematicians,dc=example,dc=com”, 
ldap.SCOPE_SUBTREE, “(uid=%(user)s)”) 

-------------------- 
$config[‘LDAP’][‘server’] = ‘ldap://ldap.forumsys.com'; 
$config[‘LDAP’][‘port’] = ‘389’; 
$config[‘LDAP’][‘user’] = ‘cn=read-only-admin,dc=example,dc=com'; 
$config[‘LDAP’][‘password’] = ‘password'; 

------------------------- 
$config[‘LDAP’][‘server’] = ‘ldap://ldap.forumsys.com/ou=mathematicians'; 
$config[‘LDAP’][‘port’] = ‘389’; 
$config[‘LDAP’][‘user’] = ‘gauss'; 
$config[‘LDAP’][‘password’] = ‘password'; 

-------------------------- 
OpenDSObject/GetObject functions, but don’t see a way to run a query with the ASDI objects. 
Set LDAP = GetObject(“LDAP:”) 
Set root = LDAP.OpenDSObject(“LDAP://ldap.forumsys.com:389″, “cn=read-only-admin,dc=example,dc=com”, “password”, 0) 
Set ou = LDAP.OpenDSObject(“LDAP://ldap.forumsys.com:389/ou=mathematicians,dc=example,dc=com””, “cn=read-only-admin,dc=example,dc=com”, “password”, 0) 
Set user = LDAP.OpenDSObject(“LDAP://ldap.forumsys.com:389/uid=riemann,dc=example,dc=com”, “cn=read-only-admin,dc=example,dc=com”, “password”, 0) 

私には何か欠けているものが必要です。任意のリソースが役立ちます

+0

** **予期しないエラーは何ですか? –

+0

正しいプロトコルを提供しようとしましたか:LdapまたはLDAPの代わりにLDAPですか?私がグーグルで行ったこのhttp://forums.asp.net/t/1026497.aspx?LDAP+Problem+with+NET+Unknown+error+0x80005000+によると、それが問題の原因になる可能性があります。 –

答えて

0

LDAPサーバーに接続するためにPrincipalContextを使用しようとしています。ここではどのように-に良い私が始める時、私は参照記事です:私は、このサーバーと多少同様の問題があったhttp://ianatkinson.net/computing/adcsharp.htm

ctx = new PrincipalContext(
    ContextType.Domain, 
    "contoso.local", 
    "OU=Security Groups,OU=Contoso Inc,DC=contoso,DC=local", 
    "contoso\sysadmin", 
    "[email protected]"); 
1

とGoogleはここに送ってくれました。

LDAPパスで大文字と小文字が区別されるという問題が1つあります。また、AuthenticationTypeも指定する必要があります。

次のコードブロックを確認してください。

string ldapServer = "LDAP://ldap.forumsys.com:389/ou=scientists,dc=example,dc=com"; 
string userName = "cn=read-only-admin,dc=example,dc=com"; 
string password = "password"; 

var dirctoryEntry = new DirectoryEntry(ldapServer, userName, password, AuthenticationTypes.ServerBind); 

try { 
    object nativeObject = dirctoryEntry.NativeObject; 
    //Rest of the logic 
} catch (Exception ex) { 
    //Handle error 
}