2017-11-17 17 views
0

PHPでLDAPに正常に接続しましたが、多くのことを試しましたが、C#で "Server is not operational" LDAPサーバーを使用できません "。ここで は、PHPのコードです:PHPでLDAPに正常に接続しましたが、C#で接続できませんでした。

<?php 
function login($username='user', $password='pass') { 
     if (empty($username) || empty($password)) { 
      throw new BadCredentialsException('Invalid username or password.'); 
     } 
     if (($ldap = @ldap_connect($url = 'ldap://ds.xyz-example.com', $port = 636)) === false) { 
      echo('Error connecting LDAP server with url %s on port %d.'); 

     } 
     if ([email protected]_bind($ldap, sprintf($dn='uid=%s,ou=People,dc=xyz-example,dc=com', $username), $password)) { 
      $error = ldap_errno($ldap); 
      if ($error === 0x31) { 
       echo('Invalid username or password.'); 

      } else { 
       echo('error during authentication with LDAP.'); 
      } 
     } 
     return true; 
    } 


login(); // call the function 
?> 

これは完璧に動作しているが、私は、C#でそれを必要とします。どうすればC#でポートとdnとユーザーを使ってパスできますか?

はここ

string ldapPath = "LDAP://ds.xyz-example.com:636/UID=user,OU=People,DC=xyz-example,DC=com"; 
      string user = "user"; 
      string password = "pass"; 

      DirectoryEntry deSSL = new DirectoryEntry(ldapPath, user, password, AuthenticationTypes.SecureSocketsLayer); 
      try 
      { 
       user = deSSL.Properties["uid"][0].ToString(); //if this works, we bound successfully 
       Response.Output.Write("Success... {0} has bound", user); 
      } 
      catch (Exception ex) 
      { 
       Response.Output.Write("Bind Failure: {0}", ex.Message); 
      } 

おかげで、事前に「サーバーが動作していない」私はC#のではなく、エラーと試みたものです!

+0

ADと一緒に 'DirectoryEntry'を使うことはできますが、一般的なLDAPリクエストでは' System.DirectoryServices.Protocols'を見てください。 [このブログ](https://auth0.com/blog/using-ldap-with-c-sharp/)も見つかりました。 – EricLavault

+0

ありがとうEricLavault、このブログは本当に役立つと思われます。 –

答えて

0

あなたのライブラリはLDAPを実装するのではなく、実際のActiveDirectoryサーバーであり、使用時には簡単には動作しないActiveDirectoryというLDAPの奇妙な非標準MicrosoftバージョンですOpenLDAPなどの非マイクロソフトのサーバーですか?

できますか?

関連する問題