Validate User Name and Password with Active Directory

If you want to authenticate user with active directory and the show the data on web page.

public bool ValidateCredentials(string username, string password)


    string adServer= "AD Server Name";

    StringBuilder sb = new StringBuilder();

    DirectoryEntry entry = new DirectoryEntry(adServer);//connect to server

    DirectorySearcher search = new DirectorySearcher(entry);

    string domain = System.Configuration.ConfigurationSettings.AppSettings["Domain"];

    using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, domain))


        return pc.ValidateCredentials(username, password);