A local error has occurred while connecting to AD in Windows 2008 server
        Posted  
        
            by Sara
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Sara
        
        
        
        Published on 2009-10-05T10:21:30Z
        Indexed on 
            2010/05/09
            21:58 UTC
        
        
        Read the original article
        Hit count: 341
        
There's Active directory on windows 2000 advance server, I have a web server on Windows 2008 server Enterprise Edition, the following code works fine in Winsows 2003 server but when I installed Win 2008 server, it gives me the following error, the webserver is not subdomain of the AD server. but they have the same range IP address.
A local error has occurred.\r\n"} System.Exception system.DirectoryServices.DirectoryServicesCOMException} I want to Authenticate Via AD from my webserver, I even test the port 389 and it was open(by telnet), I even added port 389 UDP and TCP to firewall of webserver to be sure it is open, even I turned the firewall off but nothing changed. I don't know what's wrong with Windows 2008 server that cannot run my code, I search Internet but I found nothing. any solution would be helpful. Thank you
public bool IsAuthenticated(string username, string  pwd,string group)
{
  string domainAndUsername = "LDAP://192.xx.xx.xx:389/DC=test,DC=oc,DC=com" ;
string usr="CN=" + username + ",CN=" + group;
  DirectoryEntry entry = new DirectoryEntry(domainAndUsername, usr, pwd,  AuthenticationTypes.Secure );
  try
  {
    DirectorySearcher search = new DirectorySearcher(entry);
    search.Filter = "(SAMAccountName=" + username + ")";
    SearchResult result = search.FindOne();
    if (result == null)
    {
        return false;
    }
  }
  catch (Exception ex)
  {
      return false;
  }
  return true;
}
© Stack Overflow or respective owner