Amar Bisht

Amar Bisht

  • NA
  • 159
  • 7.8k

How to authenticate AD user in window server 2008

Nov 10 2014 5:01 AM
hi guys,


When I use Ldap for Authenticate user by IP address in winow server 2012. Its working fine ,
but when when i use same code in window server 2008 ,its not working.please tell some solution . My code as below.



        Errmsg = "";
        string domainAndUsername = "192.168.0.68"+ @"\" + "amar";
        DirectoryEntry entry = new DirectoryEntry(192.168.0.68", domainAndUsername, "ABCD");
        try
        {
            // Bind to the native AdsObject to force authentication.
           // entry.AuthenticationType = AuthenticationTypes.SecureSocketsLayer;
            Object obj = entry.NativeObject;
            DirectorySearcher search = new DirectorySearcher(entry);
            search.Filter = "(SAMAccountName=" + username + ")";
            search.PropertiesToLoad.Add("cn");
            SearchResult result = search.FindOne();
            if (null == result)
            {
                return false;
            }
            // Update the new path to the user in the directory
            LdapPath = result.Path;
            string _filterAttribute = (String)result.Properties["cn"][0];
        }
        catch (Exception ex)
        {
            Errmsg = ex.Message;
            return false;
            throw new Exception("Error authenticating user." + ex.Message);
        }
        return true;
   
need your help.
Thanks and regards
      Amar