始める前に、LDAPS接続で不明なエラー(0x80005000)にアクセスしてコードを変更しましたが、問題は解決しましたが、不思議なことに戻ってきたようです。
これが良いものです:
public static bool Authenticate(string username, string password, string domain)
{
bool authentic = false;
try
{
LdapConnection con = new LdapConnection(
new LdapDirectoryIdentifier(Host, Port));
if (IsSSL)
{
con.SessionOptions.SecureSocketLayer = true;
con.SessionOptions.VerifyServerCertificate = ServerCallback;
}
con.Credential = new NetworkCredential(username, password);
con.AuthType = AuthType.Basic;
con.Bind();
authentic = true;
}
catch (LdapException)
{
return false;
}
catch (DirectoryServicesCOMException)
{ }
return authentic;
}
public static bool IsSSL
{
get
{
return ConnectionString.ToLower().Contains("ldaps");
}
}
public static string ConnectionString
{
get
{
if (string.IsNullOrEmpty(_connectionString))
_connectionString = CompleteConfiguration.GetLDAPConnectionString();
return _connectionString;
}
set { _connectionString = value; }
}
public static int Port
{
get
{
var x = new Uri(ConnectionString);
int port = 0;
if (x.Port != -1)
{
port = x.Port;
}
else
{
port = x.OriginalString.ToLower().Contains("ldaps")
? 636
: 389;
}
return port;
}
}
public static string Host
{
get
{
var x = new Uri(ConnectionString);
return x.Host;
}
}
private static bool ServerCallback(LdapConnection connection, X509Certificate certificate)
{
return true;
}
悪い点は次のとおりです。アプリケーションに対して認証しようとすると、次のエラーが発生します。正確には、これはcon.Bind()行によってトリガーされます。
[COMException(0x80005000):不明なエラー(0x80005000)] System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)+378094 System.DirectoryServices.DirectoryEntry.Bind()+36 System.DirectoryServices.DirectoryEntry.get_NativeObject()+31 Complete.Authentication .GCAuthentication.Authenticate(String username、String password、String domain)in c:\ Builds \ 6 \ Idealink.Open.Pancanal \ Panama Canal \ Sources \ Idealink.Open \ Complete.Authentication \ GCAuthentication.cs:27Complete.Authentication。 AuthenticationFactory.ValidateUserLdap(String username、String password、String domain、Boolean isValid、String usernameWithDomain)in c:\ Builds \ 6 \ Idealink.Open.Pancanal \ Panama Canal \ Sources \ Idealink.Open \ Complete.Authentication \ AuthenticationFactory.cs: 93
一部のユーザーアカウントは機能し、他のユーザーアカウントは機能しないように見えるため、非常に混乱します。ただし、上記のコードを分離されたテスト環境に配置すると、使用するアカウントに関係なく、毎回成功します。ASP.NETとIISを使用してWindows2008R2サーバーに戻すと、上記のように失敗します。ただし、失敗は一貫しています。アカウントは一貫して失敗または成功します。その観点からは、ランダム性はありません。
LDAPサーバーにはLDAPではなくLDAPSを使用してアクセスする必要があります。そのため、DirectoryEntryオブジェクトを使用できません。LDAPサーバーはクライアントによって制御されるため、再構成または変更することはできません。Webフォームでユーザー名/パスワードを取得し、LDAPサーバーでBINDを使用して資格情報を確認するだけです。
.NET 3.5を使用しており、現時点ではアップグレードできません。そのため、主な提案や議論がアップグレードである場合は、貢献を控えてください。
ありがとう、あなたが助けることができることを願っています