Gérer des objet de l'annuaire LDAP en ASP.NET [?]

Résolu
cs_eihpos Messages postés 22 Date d'inscription vendredi 1 mars 2002 Statut Membre Dernière intervention 4 février 2005 - 6 oct. 2004 à 16:16
Tanis49 Messages postés 13 Date d'inscription jeudi 2 septembre 2004 Statut Membre Dernière intervention 28 janvier 2005 - 8 juil. 2005 à 11:38
Salut à tous,

Je voudrai savoir si il est possible en ASP.NET de faire des modifs sur un objet LDAP. Il s'agit d'une application Intranet avec une page d'admin à partir de laquelle on pourrait modifier un attribut particulier des utilisateurs de l'appli. Ces utilisateurs sont dans LDAP.

Merci de votre aide,

SoPhIe
:blush)

3 réponses

cs_fabrice69 Messages postés 1765 Date d'inscription jeudi 12 octobre 2000 Statut Membre Dernière intervention 11 décembre 2013 5
14 oct. 2004 à 09:22
Inspire toi de ca, chez moi ca fonctionne dans certains cas mais pas d'autre.

----
' -----------------------------------------------------
Public Sub ModifieCompte()
' Modifie un compte avec le login transmis et toutes les infos transmises par l'objet

Dim MonEntry As New DirectoryEntry("LDAP://" & Constantes.ChaineConn, Constantes.LoginAD, Constantes.PasswordAD, AuthenticationTypes.Secure)
Dim searcher As New DirectorySearcher(MonEntry)
searcher.Filter = "(SAMAccountName=" & Trim(Login) & ")"

Dim result As SearchResult = searcher.FindOne()
Dim dsUser As New DirectoryEntry
dsUser.Username = Constantes.LoginAD
dsUser.Password = Constantes.PasswordAD
dsUser.AuthenticationType = AuthenticationTypes.Secure
Try

dsUser = result.GetDirectoryEntry()

With dsUser.Properties
'Mettre ici les valeurs des différents attributs
Dim DisplayNameString As String = ""
Dim InitialsString As String = ""

.Item("userPrincipalName").Value = UCase(Trim(Login))
.Item("SAMAccountName").Value = UCase(Trim(Login))

' ------- Nom-Prenom-Initiales -----------------------
If Trim(Nom) <> "" Then
.Item("givenname").Value = UCase(Trim(Nom))
DisplayNameString = UCase(Trim(Nom))
InitialsString = UCase(Left(Trim(Nom), 1))
End If
If Trim(Prenom) <> "" Then
.Item("sn").Value = UCase(Trim(Prenom))
DisplayNameString &= " " & UCase(Trim(Prenom))
InitialsString &= UCase(Left(Trim(Prenom), 1))
End If

If DisplayNameString <> "" Then
.Item("displayName").Value = DisplayNameString
End If

If InitialsString <> "" Then
.Item("initials").Value = InitialsString
End If

' ------- Poste Service Occupé ----------------------
If Trim(DescriptionPoste) <> "" Then
.Item("Description").Value = Trim(DescriptionPoste)
End If

If Trim(ServiceNom) <> "" Then
.Item("department").Value = UCase(Trim(ServiceNom))
End If
If Trim(ServiceLibelle) <> "" Then
.Item("title").Value = Trim(ServiceLibelle)
End If
If Trim(Bureau) <> "" Then
.Item("physicalDeliveryOfficeName").Value = Trim(Bureau)
End If

' ------- Entreprise ---------------------------------
If Trim(Entreprise) <> "" Then
.Item("Company").Value = UCase(Trim(Entreprise))
End If
If Trim(Adresse) <> "" Then
.Item("streetAddress").Value = Trim(Adresse)
End If
If Trim(Ville) <> "" Then
.Item("l").Value = Trim(Ville)
End If
If Trim(CodePostal) <> "" Then
.Item("postalCode").Value = Trim(CodePostal)
End If
If Trim(Pays) <> "" Then
.Item("c").Value = Trim(Pays)
End If
If Trim(Superieur) <> "" Then
Dim TempManagerString As String = ""
TempManagerString = "CN=" & UCase(Trim(Superieur)) & ",CN=Users,DC=" & Replace(Constantes.DomainControler, ".", ",DC=", 1, -1, CompareMethod.Text)
.Item("manager").Value = TempManagerString
End If

' ------- Coordonnées --------------------------------
If Trim(Email) <> "" Then
.Item("mail").Value = Trim(Email)
End If
If Trim(Telephone) <> "" Then
.Item("telephoneNumber").Value = Trim(Telephone)
End If
If Trim(TelPortable) <> "" Then
.Item("mobile").Value = Trim(TelPortable)
End If
If Trim(Fax) <> "" Then
.Item("facsimileTelephoneNumber").Value = Trim(Fax)
End If

End With
dsUser.CommitChanges()

Catch e As System.Runtime.InteropServices.ExternalException
Dim MonLog As New Logger("WS_CREATION_COMPTE_AD", FichierLog)
MonLog.Log("----------------------------------------------------------------------------")
MonLog.Log("Erreur dans la Modification du Compte " & Login & " | Message complet : " & e.Message.ToString & " | Date : " & Date.Now.ToString & " | Date : " & Date.Now.ToString)
MonLog.Log("Trace appli :" & e.StackTrace())
MonLog.Log("Code Erreur :" & e.ErrorCode)
MonLog.Log("Help Link :" & e.HelpLink)
MonLog.Log("----------------------------------------------------------------------------")

Catch ex As Exception
Dim MonLog As New Logger("WS_CREATION_COMPTE_AD", FichierLog)
MonLog.Log("----------------------------------------------------------------------------")
MonLog.Log("Erreur dans la Modification du Compte " & Login & " | Message complet : " & ex.Message.ToString & " | Date : " & Date.Now.ToString & " | Date : " & Date.Now.ToString)
MonLog.Log("Trace appli :" & ex.StackTrace())
MonLog.Log("Help Link :" & ex.HelpLink)
MonLog.Log("Source :" & ex.Source)
MonLog.Log("----------------------------------------------------------------------------")
Finally
dsUser.Close()
dsUser.Dispose()

MonEntry.Close()
MonEntry.Dispose()

End Try
End Sub
------

Romelard Fabrice (Alias F___)
3
cs_eihpos Messages postés 22 Date d'inscription vendredi 1 mars 2002 Statut Membre Dernière intervention 4 février 2005
14 oct. 2004 à 13:38
Merci beaucoup je vais essayer
SoPhIe
:blush)
0
Tanis49 Messages postés 13 Date d'inscription jeudi 2 septembre 2004 Statut Membre Dernière intervention 28 janvier 2005
8 juil. 2005 à 11:38
Salut a vous deux ... jessaye de faire a peut prés la même chose, mais
avant tous je cherche a differencier les entrées... notamment Dans l'AD
il y a les USER et les CONTACTS.. comment allez spécifiquement
cherhcer/modifier/créer dans l'un ou dans l'autre via l'annuaire LDAP
???....

je suppose que c'est dans la chaine de connexion mais je trouve pas...

Vive les Galères de Dev......
0
Rejoignez-nous