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.
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 = ""
' ------- 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()
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...