Check with below code.
public bool AuthenticateUser(string LDAPStr, string Username, string Password)
{
try
{
System.DirectoryServices.DirectoryEntry Entry = new System.DirectoryServices.DirectoryEntry(LDAPStr, Username, Password);
var nativeObject = Entry.NativeObject;
return true; // Correct credentials
}
catch
{
return false; // Incorrect credentials
}
}
protected void LoginButton_Click(object sender, EventArgs e)
{
if (AuthenticateUser("LDAP://example.com/DC=ad,DC=fullerton,DC=edu", txtLoginID.Text, txtPassword.Text))
{
System.Web.Security.FormsAuthentication.RedirectFromLoginPage(txtLoginID.Text, false);
Response.Redirect("~/Home.aspx");
}
}