IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

Problème d'accès aux attributs AD


Sujet :

C#

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2009
    Messages
    28
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2009
    Messages : 28
    Par défaut Problème d'accès aux attributs AD
    Bonjour,
    je voudrais accéder aux attributs d'un usager dans l'active directory : le "mailNickname" et le "displayName", pour l'afficher dans un DropDownList, mais lorsque j'affiche la liste des attributs, j'obtiens System.byte[] dans la plupart des attributs.

    homemdb - System.Byte[]
    distinguishedname - CN=xxx xxx,OU=users,OU=industrie,DC=xxx,DC=com
    st - Quebec
    company - System.Byte[]
    lastlogoff - System.Byte[]
    mailnickname - System.Byte[]
    dscorepropagationdata - System.Byte[]
    msexchhomeservername - System.Byte[]
    facsimiletelephonenumber - (xxx) xxx-xxxx
    msexchalobjectversion - System.Byte[]
    usncreated - System.Byte[]
    objectguid - System.Byte[]
    postalcode - xxx xxx
    c - CA
    whenchanged - System.Byte[]
    memberof - System.Byte[]
    msexchuseraccountcontrol - System.Byte[]
    accountexpires - System.Byte[]
    displayname - System.Byte[]
    primarygroupid - System.Byte[]
    streetaddress - System.Byte[]
    badpwdcount - System.Byte[]
    objectclass - top
    objectcategory - System.Byte[]
    instancetype - System.Byte[]
    scriptpath - System.Byte[]
    info - PC1486
    samaccounttype - System.Byte[]
    whencreated - System.Byte[]
    lastlogon - System.Byte[]
    l - xxx
    useraccountcontrol - System.Byte[]
    co - Canada
    physicaldeliveryofficename - xxx, rue Principale
    samaccountname - System.Byte[]
    sn - xxx
    givenname - xxx
    mail - xxx
    msexchmailboxsecuritydescriptor - System.Byte[]
    adspath - LDAP://CN=xxx xxx,OU=users,OU=industrie,DC=xxx,DC=com
    lockouttime - System.Byte[]
    homemta - System.Byte[]
    description - User
    msexchmailboxguid - System.Byte[]
    pwdlastset - System.Byte[]
    logoncount - System.Byte[]
    cn - xxx xxx
    codepage - System.Byte[]
    name - xxx xxx
    usnchanged - System.Byte[]
    legacyexchangedn - System.Byte[]
    proxyaddresses - System.Byte[]
    department - System.Byte[]
    userprincipalname - System.Byte[]
    badpasswordtime - System.Byte[]
    objectsid - System.Byte[]
    title - Secretaire
    mdbusedefaults - System.Byte[]
    telephonenumber - Ext: 758
    showinaddressbook - System.Byte[]
    countrycode - System.Byte[]
    textencodedoraddress - c=CA;a= ;p=xxx;o=xxx;s=xxx;g=xxx;
    lastlogontimestamp - System.Byte[]
    msexchpoliciesincluded - System.Byte[]
    ceci est dans la page sur le serveur de production

    mais lorsque j'exécute la même page sur un serveur de développement, j'obtiens toutes les informations.

    mon code est :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    public void GetUser()
    {
      DirectoryEntry objADAM = new DirectoryEntry("LDAP://dc=xxx,dc=com");
      DirectorySearcher objSearchADAM = new DirectorySearcher(objADAM);
      List<string> result = new List<string>();
     
      objSearchADAM.Filter = "(&(objectClass=user))";
      objSearchADAM.SearchScope = SearchScope.Subtree;
      SearchResultCollection objSearchResults = objSearchADAM.FindAll();
     
      SortedList list = new SortedList();
     
      ux_ListeUsager.Items.Clear();
      foreach (SearchResult res in objSearchResults)
      {
        ICollection coll = res.Properties.PropertyNames;
        string CodeUsager = "";
        string Usager = "";
        foreach (string item1 in coll)
        {
          ResultPropertyValueCollection colltest = res.Properties[item1];
          string itemtest = "";
          itemtest = Convert.ToString(colltest[0]);
          Response.Write(item1 + " - " + itemtest + "<br />");
          try
          {
            ResultPropertyValueCollection coll1 = res.Properties["mailNickname"];
            CodeUsager = coll1[0].ToString();
            ResultPropertyValueCollection coll2 = res.Properties["displayName"];
            Usager = coll2[0].ToString();
          }
          catch
          { }
        }
        Response.Write("<br />");
     
        if (!list.Contains(Usager))
          list.Add(CodeUsager, Usager);
      }
      foreach (DictionaryEntry Item in list)
      {
        ListItem newListItem = new ListItem();
        newListItem.Value = Item.Key.ToString();
        newListItem.Text = Item.Value.ToString();
        ux_ListeUsager.Items.Add(newListItem);
      }
    }
    Quelqu'un sait qu'est ce qui pourrait causer ce problème?

    Merci d'avance

  2. #2
    Expert confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Février 2005
    Messages
    5 489
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Conseil

    Informations forums :
    Inscription : Février 2005
    Messages : 5 489
    Par défaut
    http://msdn.microsoft.com/fr-fr/libr...rchresult.aspx
    A en croire la documentation, vous devez appeler la méthode "GetDirectoryEntry" pour accéder à toutes les propriétés.

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2009
    Messages
    28
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2009
    Messages : 28
    Par défaut
    Merci pour votre réponse, mais ça ne fonctionne toujours pas.
    Les "System.Byte[]" sont toujours là.

    J'ai modifié mon code pour
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    public void GetUser()
    {
      DirectoryEntry objADAM = new DirectoryEntry("LDAP://dc=xxx,dc=com");
      DirectorySearcher objSearchADAM = new DirectorySearcher(objADAM);
      List<string> result = new List<string>();
     
      objSearchADAM.Filter = "(&(objectClass=user))";
      objSearchADAM.SearchScope = SearchScope.Subtree;
      SearchResultCollection objSearchResults = objSearchADAM.FindAll();
     
      SortedList list = new SortedList();
     
      ux_ListeUsager.Items.Clear();
      foreach (SearchResult res in objSearchResults)
      {
        DirectoryEntry myDirectoryEntry = res.GetDirectoryEntry();
        string CodeUsager = "";
        string Usager = "";
     
        try
        {
          //CodeUsager = myDirectoryEntry.Properties["mailNickname"].Value.ToString();
          //Usager = myDirectoryEntry.Properties["displayName"].Value.ToString();
     
          ResultPropertyCollection myResultPropColl = res.Properties;
          foreach (string myKey in myResultPropColl.PropertyNames)
          {
            Response.Write(myKey + " = ");
            foreach (Object myCollection in myResultPropColl[myKey])
            Response.Write(" " + myCollection);
            Response.Write("<br />");
          }
          Response.Write("<br />");
        }
        catch
        { }
     
        //if (!IsPostBack)
        //    Response.Write(CodeUsager + " - " + Usager + "<br />");
     
        if (!list.Contains(Usager))
          list.Add(CodeUsager, Usager);
      }
     
      foreach (DictionaryEntry Item in list)
      {
        ListItem newListItem = new ListItem();
        newListItem.Value = Item.Key.ToString();
        newListItem.Text = Item.Value.ToString();
        ux_ListeUsager.Items.Add(newListItem);
      }
    }
    et le résultat est toujours
    homemdb = System.Byte[]
    distinguishedname = CN=xxx xxx,OU=laboratoire,OU=xxx,OU=divisions,DC=xxx,DC=com
    st = Quebec
    company = System.Byte[]
    lastlogoff = System.Byte[]
    mailnickname = System.Byte[]
    dscorepropagationdata = System.Byte[] System.Byte[] System.Byte[] System.Byte[] System.Byte[]
    msexchhomeservername = System.Byte[]
    facsimiletelephonenumber = (xxx) xxx-xxxx
    msexchalobjectversion = System.Byte[]
    usncreated = System.Byte[]
    objectguid = System.Byte[]
    postalcode = xxx xxx
    c = CA
    whenchanged = System.Byte[]
    memberof = System.Byte[] System.Byte[] System.Byte[] System.Byte[] System.Byte[] System.Byte[] System.Byte[] System.Byte[] System.Byte[] System.Byte[] System.Byte[]
    msexchuseraccountcontrol = System.Byte[]
    accountexpires = System.Byte[]
    displayname = System.Byte[]
    primarygroupid = System.Byte[]
    streetaddress = System.Byte[]
    badpwdcount = System.Byte[]
    objectclass = top person organizationalPerson user
    objectcategory = System.Byte[]
    instancetype = System.Byte[]
    scriptpath = System.Byte[]
    info = PC1329
    samaccounttype = System.Byte[]
    whencreated = System.Byte[]
    lastlogon = System.Byte[]
    l = xxx
    useraccountcontrol = System.Byte[]
    co = Canada
    physicaldeliveryofficename = xxx, rue Principale
    samaccountname = System.Byte[]
    sn = xxx
    givenname = xxx
    mail = xxx
    msexchmailboxsecuritydescriptor = System.Byte[]
    adspath = LDAP://CN=xxx xxx,OU=laboratoire,OU=xxx,OU=divisions,DC=xxx,DC=com
    lockouttime = System.Byte[]
    homemta = System.Byte[]
    description = User
    msexchmailboxguid = System.Byte[]
    pwdlastset = System.Byte[]
    logoncount = System.Byte[]
    cn = xxx xxx
    codepage = System.Byte[]
    name = xxx xxx
    usnchanged = System.Byte[]
    legacyexchangedn = System.Byte[]
    proxyaddresses = System.Byte[] System.Byte[] System.Byte[] System.Byte[]
    department = System.Byte[]
    userprincipalname = System.Byte[]
    badpasswordtime = System.Byte[]
    objectsid = System.Byte[]
    title = Technicienne
    mdbusedefaults = System.Byte[]
    telephonenumber = Ext: 784
    showinaddressbook = System.Byte[] System.Byte[]
    countrycode = System.Byte[]
    textencodedoraddress = c=CA;a= ;p=xxx;o=xxx;s=xxx;g=xxx;
    lastlogontimestamp = System.Byte[]
    msexchpoliciesincluded = System.Byte[]
    donc les données dans le SearchResult ne sont pas les bons, l'utilisation du GetDirectoryEntry() n'a pas fait de changement.

  4. #4
    Expert confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Février 2005
    Messages
    5 489
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Conseil

    Informations forums :
    Inscription : Février 2005
    Messages : 5 489
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    PropertyCollection PropColl = myDirectoryEntry.Properties;
          foreach (string myKey in PropColl.PropertyNames)
          {
    ...
          }
    ???

  5. #5
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2009
    Messages
    28
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2009
    Messages : 28
    Par défaut
    Merci encore
    J'ai testé avec ce code puis les résultats sont différents, mais certaines données ne s'affichent toujours pas.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    System.DirectoryServices.PropertyCollection PropColl = myDirectoryEntry.Properties;
    foreach (string myKey in PropColl.PropertyNames)
    {
      Response.Write(myKey + " = ");
      try
      {
        foreach (Object myCollection in PropColl[myKey])
          Response.Write(" " + myCollection);
      }
      catch
      { }
      Response.Write("<br />");
    }
    objectClass = top person organizationalPerson user
    cn = xxx
    distinguishedName = CN=xxx,CN=Users,DC=xxx,DC=com
    instanceType =
    whenCreated =
    whenChanged =
    displayName =
    uSNCreated =
    securityProtocol =
    memberOf =
    uSNChanged =
    homeMTA =
    proxyAddresses =
    homeMDB =
    mDBUseDefaults =
    mailNickname =
    replicatedObjectVersion =
    name = claude
    objectGUID =
    userAccountControl =
    badPwdCount =
    codePage =
    countryCode =
    badPasswordTime =
    lastLogoff =
    lastLogon =
    logonHours =
    pwdLastSet =
    primaryGroupID =
    userParameters =
    objectSid =
    adminCount =
    accountExpires =
    logonCount =
    sAMAccountName =
    sAMAccountType =
    legacyExchangeDN =
    objectCategory =
    isCriticalSystemObject =
    mSMQSignCertificates =
    mSMQDigests =
    msNPAllowDialin =
    lastLogonTimestamp =
    textEncodedORAddress = c=CA;a= ;p=xxx;o=xxx;s=Administrator;
    mail = xxx
    msExchPoliciesIncluded =
    msExchHomeServerName =
    replicationSignature =
    msExchALObjectVersion =
    msExchADCGlobalNames =
    msExchHideFromAddressLists =
    msExchMailboxSecurityDescriptor =
    msExchUserAccountControl =
    msExchMailboxGuid =
    dLMemDefault =
    nTSecurityDescriptor =
    puis si j'enlève le try catch, l'erreur qui survient est celle-ci :
    Unknown error (0x8000500c)
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Runtime.InteropServices.COMException: Unknown error (0x8000500c)

    Source Error:


    Line 90: //try
    Line 91: //{
    Line 92: foreach (Object myCollection in PropColl[myKey])
    Line 93: Response.Write(" " + myCollection);
    Line 94: //}
    il faut aussi tenir compte de ce que j'ai mentionné plus tôt
    ceci est dans la page sur le serveur de production

    mais lorsque j'exécute la même page sur un serveur de développement, j'obtiens toutes les informations.
    si ça peut aider quelqu'un à m'aider

  6. #6
    Expert confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Février 2005
    Messages
    5 489
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Conseil

    Informations forums :
    Inscription : Février 2005
    Messages : 5 489
    Par défaut
    Avez-vous un compte avec assez de droits en production ?
    http://www.keyongtech.com/307379-exception-0x8000500c

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. problème d'acces aux attributs d'un objet [arduino].
    Par Luke spywoker dans le forum Débuter
    Réponses: 11
    Dernier message: 18/09/2013, 20h02
  2. Réponses: 2
    Dernier message: 03/06/2009, 15h56
  3. Problème d'accés aux attributs de ma classe
    Par Invité dans le forum Débuter
    Réponses: 3
    Dernier message: 08/07/2008, 22h49
  4. Problème d'acces aux attributs
    Par parano dans le forum C++
    Réponses: 3
    Dernier message: 16/03/2007, 16h29
  5. [TOMCAT] JSP problème d'accès aux méthodes d'une classes
    Par gunnm dans le forum Tomcat et TomEE
    Réponses: 3
    Dernier message: 22/05/2004, 14h02

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo