System.DirectoryServices - Le serveur n'est pas opérationnel

J'obtiens une erreur par un site web, sur lequel j'ai utiliser l'Authentification Windows.

Choses étranges:

  • Se produit uniquement si l'utilisateur n'est pas encore enregistré dans la base de données (nouveaux et inconnus de l'utilisateur)
  • Apparaît uniquement sur le système live, tout beaux sur le développement local environnement

C'est ce que je reçois dans un enregistrement mail:

Source : Système D'.DirectoryServices

Message: Le serveur n'est pas opérationnel.

Trace:
au Système.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
au Système.DirectoryServices.DirectoryEntry.Bind()
au Système.DirectoryServices.DirectoryEntry.get_AdsObject()
au Système.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)
au Système.DirectoryServices.DirectorySearcher.FindOne()
au Smarthouse.Les laboratoires.DataAccess.UserListManager.SaveUser(String windowsUserName)

C'est comment je mettre en œuvre DirectorySearch:

private void SaveUser(string windowsUserName)
{
    string[] domainAndUser = windowsUserName.Split('\\');
    string domain = domainAndUser[0];
    string username = domainAndUser[1];

    DirectoryEntry entry = new DirectoryEntry("LDAP://" + domain);
    DirectorySearcher search = new DirectorySearcher(entry);

    try
    {
        //Bind to the native AdsObject to force authentication.
        search.Filter = "(SAMAccountName=" + username + ")";
        search.PropertiesToLoad.Add("cn");
        search.PropertiesToLoad.Add("sn");
        search.PropertiesToLoad.Add("givenName");
        search.PropertiesToLoad.Add("mail");

        SearchResult result = search.FindOne();

        if (result == null)
        {
            throw new Exception("No results found in Windows authentication.");
        }

        User userToSave = new User();
        userToSave.FirstName = (String) result.Properties["givenName"][0];
        userToSave.LastName = (String) result.Properties["sn"][0];
        userToSave.Email = (String) result.Properties["mail"][0];
        userToSave.Username = windowsUserName;
        userToSave.Guid = Guid.NewGuid();

        SaveUser(userToSave);
    }
    catch (Exception ex)
    {
        throw new Exception("Error authenticating user. " + ex.Message, ex);
    }
    finally
    {
        //Dispose service and search to prevent leek in memory
        entry.Dispose();
        search.Dispose();
    }
}

Si plus d'exemples de code sont nécessaires dites-le moi.

source d'informationauteur Tai Kahar