none
Trabajo con usuarios en Directorio Activo ADSI RRS feed

  • Pregunta

  •  

    QUisiera saber si alguien conoce un ejemplo de codigo fuente, para crear y gestionan usuarios del AD en paginas ASP, para usarlo a traves de un website
    martes, 8 de enero de 2008 10:31

Respuestas

  • hola,

     

    aqui te dejo un ejemplo de codigo para recuperar el nombre y apellido de un usuario del AD, basandose en su login.

    Bloque de código

     

    Imports System.DirectoryServices
    ...
    ' Le code de la fonction simple
    ' -----------------------------------------------------
    Public ChaineConn As String = "LDAP://MonControleurdeDomaineActiveDirectory"
    Public rootEntry As New DirectoryEntry(ChaineConn, LoginAD, PasswordAD)
    Public Login As String = ""
    Public Nom As String = ""
    Public Prenom As String = ""
    Public Telephone As String = ""
    Public Email As String = ""
    Public Bureau As String = ""
    Public Initials As String = ""
    Public Description As String = ""
    Public Entreprise As String = ""
    Public Service As String = ""
    ' -----------------------------------------------------
    Public Sub CherchePersonne(ByVal LeLogin As String)
     ' Cherche les Informations Sur le Compte suivant le Login Transmis
     Dim searcher As New DirectorySearcher(rootEntry)
     ' Mettre ici les valeurs des différents attributs
     searcher.PropertiesToLoad.Add("cn")
     searcher.PropertiesToLoad.Add("givenname")
     searcher.PropertiesToLoad.Add("sn")
     searcher.PropertiesToLoad.Add("telephoneNumber")
     searcher.PropertiesToLoad.Add("mail")
     searcher.PropertiesToLoad.Add("physicalDeliveryOfficeName")
     searcher.PropertiesToLoad.Add("Initials")
     searcher.PropertiesToLoad.Add("Description")
     searcher.PropertiesToLoad.Add("department")
     searcher.PropertiesToLoad.Add("Company")
     searcher.Filter = "(&(anr=" & LeLogin & ")(objectCategory=person))"
     Dim results As SearchResultCollection
     results = searcher.FindAll()
     If results.Count > 0 Then
       Dim result As SearchResult
       For Each result In results
         Login = CStr(result.Properties("cn")(0))
         If Not (result.Properties("givenname") Is Nothing) Then
           Nom = Trim(CStr(result.Properties("givenname")(0)))
         End If
         If Not (result.Properties("sn") Is Nothing) Then
           Prenom = Trim(CStr(result.Properties("sn")(0)))
         End If
         If Not (result.Properties("telephoneNumber") Is Nothing) Then
           Telephone = Trim(CStr(result.Properties("telephoneNumber")(0)))
         End If
         If Not (result.Properties("mail") Is Nothing) Then
           Email = Trim(CStr(result.Properties("mail")(0)))
         End If
         If Not (result.Properties("physicalDeliveryOfficeName") Is Nothing) Then
           Bureau = Trim(CStr(result.Properties("physicalDeliveryOfficeName")(0)))
         End If
         If Not (result.Properties("Initials") Is Nothing) Then
           Initials = Trim(CStr(result.Properties("Initials")(0)))
         End If
         If Not (result.Properties("Description") Is Nothing) Then
           Description = Trim(CStr(result.Properties("Description")(0)))
         End If
         If Not (result.Properties("Company") Is Nothing) Then
           Entreprise = Trim(CStr(result.Properties("Company")(0)))
         End If
         If Not (result.Properties("department") Is Nothing) Then
           Service = Trim(CStr(result.Properties("department")(0)))
         End If
       Next
     End If
    End Sub

     

     


      este codigo viene de esta pagina, 'en frances:

    http://www.aspfr.com/codes/ASP-NET-COMMENT-QUESTIONNER-CONTROLEUR-DOMAINE-ACTIVE-DIRECTORY_8999.aspx

     

    aunque sea solo como ejemplo, puedes ver los que hay en el sitio, muchos recursos de codigo fuente en ejemplo, y creo, que se pueda entender, asi no hables frances...

     

    cualquier duda, no hesites en preguntar.

     

     

    un saludo cordial,

     

    Pierre.

    martes, 8 de enero de 2008 12:32