Bonjour,
Je suis entrain de faire un site intranet qui peut être consulté à partir de l'extérieur mais pour cela il faut s'identifier.
L'identification doit se faire via un Active Directory mais je n'y arrive pas. Je fais donc appel à votre aide puisqu'après plusieurs heures de recherches, je n'ai toujours pas trouvé la solution miracle.
Donc voici le formulaire de connexion :
Ma classe Active Directory :
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 <asp:Table ID="TblLogin" runat="server" HorizontalAlign="Center"> <asp:TableRow> <asp:TableCell ColumnSpan="2" HorizontalAlign="Center">Veuillez vous identifier avec vos identifiants de session windows</asp:TableCell> </asp:TableRow> <asp:TableRow> <asp:TableCell HorizontalAlign="Left">Nom d'utilisateur : </asp:TableCell> <asp:TableCell HorizontalAlign="Left"><asp:TextBox ID="txtLogin" runat="server" Width="200"/></asp:TableCell> </asp:TableRow> <asp:TableRow> <asp:TableCell HorizontalAlign="Left">Mot de passe : </asp:TableCell> <asp:TableCell HorizontalAlign="Left"><asp:TextBox ID="txtPassword" runat="server" Width="200" TextMode="Password"></asp:TextBox></asp:TableCell> </asp:TableRow> <asp:TableRow> <asp:TableCell ColumnSpan="2" HorizontalAlign="Center"> <asp:Button id="btnConnexion" Text="Se connecter" runat="server" /> </asp:TableCell> </asp:TableRow> </asp:Table>
Et enfin le code qui est exécuté lors du clic sur le bouton du formulaire :
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 Imports Microsoft.VisualBasic Imports System.DirectoryServices Public Class ActiveDirectory Private o_Directory As DirectoryEntry Public Sub New(ByVal TheAdresseAccess As String, ByVal TheLogin As String, ByVal ThePassword As String) Try o_Directory = New DirectoryEntry("LDAP://" & TheAdresseAccess, TheLogin, ThePassword) Catch Ex As Exception MsgBox(Ex.Message) End Try End Sub Public Function Connexion(ByVal TheUser As String, ByVal ThePassword As String) As Boolean Dim Result As New DirectorySearcher(o_Directory) Result.Filter = "(SAMAccountName=" & TheUser & ")(password=" & ThePassword & ")" Dim Resultat As SearchResult = Nothing ' On exécute la recherche et on ne récupère que le premier élément retourné Try Resultat = Result.FindOne Catch ex As Exception MsgBox("Erreur Active Directory - Connexion impossible : " & ex.ToString) End Try Return IIf(Resultat Is Nothing, False, True) End Function End Class
Merci d'avance à ceux qui pourront m'aider.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 Dim s_User As String = txtLogin.Text Dim s_Password As String = txtPassword.Text If s_User.Length > 0 And s_Password.Length > 0 Then Dim o_AD As New ActiveDirectory(WebConfigurationManager.AppSettings("ActiveDirectory"), _ WebConfigurationManager.AppSettings("ActiveDirectory"), _ WebConfigurationManager.AppSettings("ActiveDirectory")) If (o_AD.Connexion(s_User, s_Password)) Then ... End If
Partager