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#のではなく、エラーと試みたものです!
ADと一緒に 'DirectoryEntry'を使うことはできますが、一般的なLDAPリクエストでは' System.DirectoryServices.Protocols'を見てください。 [このブログ](https://auth0.com/blog/using-ldap-with-c-sharp/)も見つかりました。 – EricLavault
ありがとうEricLavault、このブログは本当に役立つと思われます。 –