のドメインコントローラに対してユーザー資格情報を検証します.Windowsユーザー、ローカルユーザー、およびドメインユーザーに対してユーザー名とパスワードによってユーザーを認証しようとしています。 I already tried this solution。 PrincipalContextを得るために、私のコードは次のようになります:ローカルWindowsユーザーのユーザーとのActiveDirectoryでのリモートユーザのために正常に動作します.NETアプリケーションで
protected static PrincipalContext TryCreatePrincipalContext(String domain)
{
var computerDomain = TryGetComputerDomain();
if (String.IsNullOrEmpty(domain) && String.IsNullOrEmpty(computerDomain))
return new PrincipalContext(ContextType.Machine);
else if (String.IsNullOrEmpty(domain))
return new PrincipalContext(ContextType.Domain, computerDomain);
else
return new PrincipalContext(ContextType.Domain, domain);
}
protected static String TryGetComputerDomain()
{
try
{
var domain = Domain.GetComputerDomain();
return domain.Name;
} catch
{
return null;
}
}
。しかし、マシン上で認証を実行しようとすると、それはActiveDirectory以外のドメインマスターに結合されます。 Sambaサーバは、私は次の例外を取得:
System.DirectoryServices.AccountManagement.PrincipalServerDownException: Mit dem Server konnte keine Verbindung hergestellt werden. --->
System.DirectoryServices.Protocols.LdapException: Der LDAP-Server ist nicht verfügbar.
bei System.DirectoryServices.Protocols.LdapConnection.Connect()
bei System.DirectoryServices.Protocols.LdapConnection.SendRequestHelper(DirectoryRequest request, Int32& messageID)
bei System.DirectoryServices.Protocols.LdapConnection.SendRequest(DirectoryRequest request, TimeSpan requestTimeout)
bei System.DirectoryServices.Protocols.LdapConnection.SendRequest(DirectoryRequest request)
bei System.DirectoryServices.AccountManagement.PrincipalContext.ReadServerConfig(String serverName, ServerProperties& properties)
--- Ende der internen Ausnahmestapelüberwachung ---
bei System.DirectoryServices.AccountManagement.PrincipalContext.ReadServerConfig(String serverName, ServerProperties& properties)
bei System.DirectoryServices.AccountManagement.PrincipalContext.DoServerVerifyAndPropRetrieval()
bei System.DirectoryServices.AccountManagement.PrincipalContext..ctor(ContextType contextType, String name, String container, ContextOptions options, String userName, String password)
bei System.DirectoryServices.AccountManagement.PrincipalContext..ctor(ContextType contextType, String name)
bei DomainAuthTest.DomainAuthenticator.TryCreatePrincipalContext(String domain)
bei DomainAuthTest.DomainAuthenticator.Authenticate(String domainUser, String password)
bei DomainAuthTest.Program.Main(String[] args)
だから、PrincipalContextがContextType.Domainの場合にLDAPを使用しようとしているようです。 ContextType.Machineを使用しようとすると、PrincipalContextがマシンに直接接続しようとするため、ワークグループ/ドメイン名を使用できません。そのマシンに同じマシンからのウィンドウがすでに接続されていると、それは失敗します。
だから私の質問は次のとおりです。
- 必然のActiveDirectoryに基づいていないドメインのマスター、に対して資格情報のドメイン、ユーザー名とパスワードでユーザーを認証するためにどのように?
- 上記のタスクを実行するための管理APIがありますか?
- 管理された基礎クラスがない場合、それを行う正しい方向は何ですか?
ありがとうございます。完全を期すために
お返事をあなたに天使をありがとうございました。残念ながら、それは問題の問題を解決しません。現在のディレクトリ - サーバーに対して認証を行います。 IMHO System.DirectoryServices.AccountManagement.PrincipalContextクラスは、マシンがActive-DirectoryのないWIN2000/Sambaドメインに参加している場合、またはドメインに参加していなくても機能しません。 「advapi32.dll」の「LogonUser」メソッドは、これらのケースごとに透過的です。 –