DirectoryEntry メソッドを使用する C# Web アプリで LDAP ログインをセットアップしています。以下のコードは、私がこれまでに持っているものです。これにより、AD アカウントを持つすべてのユーザーがログインできるようになります。「commonusers」という名前のグループの人に限定する必要があります。
public Boolean ValidateUser(string userName, string password)
{
string path = "LDAP://domain.company.org";
DirectoryEntry dirEntry = new DirectoryEntry(path, userName, password, AuthenticationTypes.Secure);
try
{
DirectorySearcher dirSearcher = new DirectorySearcher(dirEntry);
dirSearcher.FindOne();
return true;
// If it returns the data then the User is validated otherwise it will automatically shift to catch block and return false
}
catch
{
return false;
}
ログイン ボタンは、次のコードを使用します。
protected void Button1_Click(object sender, EventArgs e)
{
{
Boolean boolresult = ValidateUser(TextBox_username.Text, TextBox_password.Text);
if (boolresult)
{
Label_loginstatus.Text = "Redirecting";
Response.Redirect("medsearch.aspx");
}
else
{
Label_loginstatus.Text = "Invalid username/password! Please try again.";
}
}
}
これらの機能の 1 つに、「commonusers」グループのユーザー アカウントをチェックする機能を追加することは可能ですか?