Viewing source for Recipe2002VB.aspx
<%@ Page %>
<script Language="vb" runat="server">
Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
'Put user code to initialize the page here
If Not ValidateUser("Login", "Password") Then
'redirect to another page, login failed
Function ValidateUser(ByVal Login As String, ByVal Password As String) As Boolean
Dim Entry As DirectoryEntry
Entry = New DirectoryEntry("LDAP://DomainName", Login, Password)
'DirectorySearcher can only be used when using the LDAP provider.
'If we were searching for something specific we could put it in the path above.
'Of course you don�t need to do it there; you could also use the filter property of the DirectorySearcher object.
Dim Search As DirectorySearcher = New DirectorySearcher(Entry)
'Notice that now we want to retrieve the results, we then must use the SearchResult object.
'When retrieving results there are two objects �SearchResult� and �SearchResults� depending on how you retrieve the results depends will tell what to use.
Dim results As SearchResult = Search.FindOne
'Since we are only looking to authenticate we don�t want to take too long so we are only searching for one, which in this case decides which search object to use.
'If it authenticates and the user and password is valid then you return true, else it will throw an Exception and return false
'Finally we close the entry which will close all resources using entry