0

次のコードを使用してADユーザーを検証しています

string strLDAP = "LDAP://dc=ADServerIP/cn=Users,DC=Domain;
DirectoryEntry entry = new DirectoryEntry(strLDAP, usr, pwd);
object nativeObject = entry.NativeObject;
return true;

実行時に次の例外が発生します

object nativeObject = entry.NativeObject;

System.Runtime.InteropServices.COMException (0x80005000):
System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
での不明なエラー (0x80005000) System.DirectoryServices.DirectoryEntry.Bind()
で System.DirectoryServices.DirectoryEntry.get_NativeObject()

同じコードが別の AD サーバーで機能しています。問題は何ですか?

4

1 に答える 1

7

.NET 3.5 以降で作業していますか? その場合は、System.DirectoryServices.AccountManagement 名前空間を使用して、資格情報を簡単に確認できます。

// create a "principal context" - e.g. your domain (could be machine, too)
using(PrincipalContext pc = new PrincipalContext(ContextType.Domain, "YOURDOMAIN", usr, pwd))
{
    // validate the credentials
    bool isValid = pc.ValidateCredentials("myuser", "mypassword");
}

シンプルで信頼性が高く、100% C# で管理されたコードです。これ以上何を求めることができますか? :-)

ここでそれについてすべて読んでください:

于 2012-06-04T05:04:34.590 に答える