:Active Directoryを使用している場合、あなたはこのようなものを使用することができ
using System.Security;
using System.DirectoryServices.AccountManagement;
public struct Credentials
{
public string Username;
public string Password;
}
public class Domain_Authentication
{
public Credentials Credentials;
public string Domain;
public Domain_Authentication(string Username, string Password, string SDomain)
{
Credentials.Username = Username;
Credentials.Password = Password;
Domain = SDomain;
}
public bool IsValid()
{
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, Domain))
{
// validate the credentials
return pc.ValidateCredentials(Credentials.Username, Credentials.Password);
}
}
}
をこれを行う最善の方法は、WNetUseConnection、最も直接的な方法を可能にするWin32 APIを使用することです。実際には、あなたは、
net use \\server password /user:myUserName
を呼び出すために、このAPIを行うことを意図しているものです
をしようとしています。
これの良い例はthis questionです。
、最も単純な認証コードが
private static bool AuthenticateUserOnRemote(string server, string userName, string password)
{
var connected = PinvokeWindowsNetworking.connectToRemote(server, userName, password);
var disconnected = PinvokeWindowsNetworking.disconnectRemote(server);
return connected == null;
}
あなたは、接続文字列は、LDAPサーバに到達するために働いていることを確認したときに成功した
PinvokeWindowsNetworking
関数はnullを返しますので?ディレクトリサービスを使用しているのですか?または、これをアプリの設定ファイルまたはWeb設定ファイルのWindows認証モードで行いますか? – BrianEXAMPLEMACHINEはドメインコントローラですか?そうでなければ、それはあなたの問題かもしれません。ネットワーク上に表示されているため、正規の(つまりサーバー以外の)マシンで資格情報を検証できるかどうかはわかりません。それはエラーメッセージがあなたに伝えていることです、と私は思います。 – ken
それが問題です。私はドメインコントローラを持っていません。通常のマシンで資格情報を検証したいのは、ネットワーク上に表示されているからです。 – Alexandru