Rechercher : dans
Par :

Active Directory et ASP

Dernière réponse le 28 mai 2002 à 01:25:06 Robert PARLSON, le 27 mai 2002 à 17:21:31 
 Signaler ce message aux modérateurs

Bonjour,

Quelqu'un peut -il m'aider en me donnant un exemple de code ASP ou VB, effectuant le traitement suivant :

Authentifier des utilisateurs en vérifiant leur présence dans la base de données utilisateurs d'Active Directory.

Merci d'avance

Robert

Meilleures réponses pour « Active Directory et ASP » dans :
Active Directory Voir Présentation de Active Directory Active Directory est le nom du service d'annuaire de Microsoft apparu dans le système d'exploitation Microsoft Windows Server 2000. Le service d'annuaire Active Directory est basé sur les standards TCP/IP : DNS,...
Principes d'Active Directory Voir Principe de fonctionnement d'Active Directory Active Directory permet de représenter et de stocker les éléments constitutifs du réseau (les ressources informatiques mais également les utilisateurs) sous formes d'objets, c'est-à-dire un ensemble...
Active Directory et le DNS Voir Notion d'espace de nom Active Directory constitue un espace de nom homogène, c'est-à-dire que toute ressource peut être identifiée de façon unique. DN RDN Plus d'informations Vue d'ensemble de Active Directory Architecture Active Directory

1

 kami58, le 28 mai 2002 à 01:25:06
  • +1

V'là ce qui traine chez Microsoft pour 'Example Code for Searching for Users' ...

URL = http://msdn.microsoft.com/library/default.asp?url=/library/e­n-us/netdir/ad/example_code_for_searching_for_users.asp

------------------------------------------------------------­---------------

Dim Con As ADODB.Connection
Dim ocommand As ADODB.Command
Dim gc As IADs

On Error Resume Next
'Maximum number of items to list on a msgbox.
MAX_DISPLAY = 5

'Prompt for surname to search for.
strName = InputBox("This routine searches in the current domain for users with the specified surname." & vbCrLf & vbCrLf &"Specify the surname:")

If strName = "" Then
msgbox "No surname was specified. The routine will search for all users."
End If


'Create ADO connection object for Active Directory
Set Con = CreateObject("ADODB.Connection")
If (Err.Number <> 0) Then
BailOnFailure Err.Number, "on CreateObject"
End If
Con.Provider = "ADsDSOObject"
If (Err.Number <> 0) Then
BailOnFailure Err.Number, "on Provider"
End If
Con.Open "Active Directory Provider"
If (Err.Number <> 0) Then
BailOnFailure Err.Number, "on Open"
End If

'Create ADO command object for the connection.
Set ocommand = CreateObject("ADODB.Command")
If (Err.Number <> 0) Then
BailOnFailure Err.Number, "on CreateObject"
End If
ocommand.ActiveConnection = Con
If (Err.Number <> 0) Then
BailOnFailure Err.Number, "on Active Connection"
End If

'Get the ADsPath for the domain to search.
Set root = GetObject("LDAP://rootDSE")
If (Err.Number <> 0) Then
BailOnFailure Err.Number, "on GetObject for rootDSE"
End If
sDomain = root.Get("defaultNamingContext")
If (Err.Number <> 0) Then
BailOnFailure Err.Number, "on Get on defaultNamingContext"
End If
Set domain = GetObject("LDAP://" & sDomain)
If (Err.Number <> 0) Then
BailOnFailure Err.Number, "on GetObject for domain"
End If

'Build the ADsPath element of the commandtext
sADsPath = "<" & domain.ADsPath & ">"

'Build the filter element of the commandtext
If (strName = "") Then
sFilter = "(&(objectCategory=person)(objectClass=user))"
Else
sFilter = "(&(objectCategory=person)(objectClass=user)(sn=" & strName & "))"
End If

'Build the returned attributes element of the commandtext.
sAttribsToReturn = "name,distinguishedName"

'Build the depth element of the commandtext.
sDepth = "subTree"

'Assemble the commandtext.
ocommand.CommandText = sADsPath & ";" & sFilter & ";" & sAttribsToReturn & ";" & sDepth
If (Err.Number <> 0) Then
BailOnFailure Err.Number, "on CommandText"
End If
'Display
show_items "CommandText: " & ocommand.CommandText, ""

'Execute the query.
Set rs = ocommand.Execute
If (Err.Number <> 0) Then
BailOnFailure Err.Number, "on Execute"
End If

strText = "Found " & rs.RecordCount & " Users in the domain:"
intNumDisplay = 0
intCount = 0

' Navigate the record set
rs.MoveFirst
While Not rs.EOF
intCount = intCount + 1
strText = strText & vbCrLf & intCount & ") "
For i = 0 To rs.Fields.Count - 1
If rs.Fields(i).Type = adVariant And Not (IsNull(rs.Fields(i).Value)) Then
strText = strText & rs.Fields(i).Name & " = "
For j = LBound(rs.Fields(i).Value) To UBound(rs.Fields(i).Value)
strText = strText & rs.Fields(i).Value(j) & " "
Next
Else
strText = strText & rs.Fields(i).Name & " = " & rs.Fields(i).Value & vbCrLf
End If
Next
intNumDisplay = intNumDisplay + 1
'Display in msgbox if there are MAX_DISPLAY items to display
If intNumDisplay = MAX_DISPLAY Then
Call show_items(strText, "Users in domain")
strText = ""
intNumDisplay = 0
End If
rs.MoveNext
Wend

show_items strText, "Users in domain"
'''''''''''''''''''''''''''''''''''''''
'Display subroutines
'''''''''''''''''''''''''''''''''''''''
Sub show_items(strText, strName)
MsgBox strText, vbInformation, "Search domain for users with Surname " & strName
End Sub

Sub BailOnFailure(ErrNum, ErrText) strText = "Error 0x" & Hex(ErrNum) & " " & ErrText
MsgBox strText, vbInformation, "ADSI Error"
WScript.Quit
End Sub

Envoyé par Alexandre GROLLEAU
Alias kami58

Répondre à kami58
Collection CommentÇaMarche.net