Figure 1   Members Class Attributes

Attribute Description
givenName First name
sn Last name
mail Email address
telephoneNumber Phone number
cn Common name (used to identify members)
guid Globally unique identifier (used to identify members)
c Country name
homePage URL of home page
userPassword User's password
street Street address
l City (L, as in location)
st State
postalCode Zip code


Figure 2    Microsoft Access versus SQL Server

Microsoft Access SQL Server
Size limitation of 1GB No size limitation
Should not create an entry with an RDN over 230 characters in length Can create entries up to 255 characters in length
Cannot use search strings containing % (percent) or _ (underscore) characters Can use search strings containing % (percent) or _ (underscore) characters
Code page is the same as that for the computer Code page is determined when the database is set up
One LDAP service must reside on each computer containing Microsoft Access LDAP service does not have to be on the same computer
Must shut down the LDAP service to back up the database You do not have to shut down the LDAP service to back up the database
You cannot write an attribute value longer than 4095 characters to a Membership Directory using Microsoft Access N/A


Figure 4   AUOUser


 <%
 ' Always trap errors
 On Error Resume Next
 
 ' Dimension some variables
 Dim AUOUser     ' AUO User object
 Dim item        ' Used to loop through collection
 
 ' Create AUOUser object and trap errors
 Set AUOUser = Server.CreateObject("Membership.UserObjects.1")
 If Err.Number <> 0 Then
 Response.Write "Error: A fatal error has occurred, the AUO user object was not successfully created."
 Response.End
 End If
 
 ' Read variables from Post and add to DS
 For Each item in Request.Form
     If Not item = "SUBMIT" Then        ' Don't process Submit
         If Request.Form("item") = "" Then
             ' Item has no data, remove it
               AUOUser.putEX 1, cstr(item), cstr(Request.Form(item))
         Else
             ' Item has data add/update it
               AUOUser.put cstr(item), cstr(Request.Form(item))
         End If
     End If
 Next
 
 ' Call SetInfo and Trap Errors
 AUOUser.SetInfo
 If Err.Number <> 0 Then
     Response.Write "Error: Call to SetInfo failed."
 Else
     Response.Write "Success, all attributes updated!"
 End If
 %>

Figure 5   Common AUO Methods

Method Parameters Description
Get VARIANT(Get[in] BSTR bstrName) Used to retrieve items; for example: AUOUser.get "givenName".
Put Void Put([in] BSTR bstrName,
             [in] VARIANT vProp)
Used to add items; for example: AUOUser.put "givenName", "Robert".
SetInfo Void SetInfo() Used to set the information; usually called after series of puts.
AdsPath BSTR AdsPath() Returns the Active Directory Service path to the object.
PutEX Void PutEx([in] long lngControlCode,
                [in] BSTR bstrName,
                [in] VARIANT vProp)
Put Extended, can be used to remove attribute data from a class; for example: AUOUser.PutEX 1, "givenName", "Robert".
MoveHere IDispatch* CopyHere([in] BSTR SourceName,
                              [in] BSTR NewName)
Used to move an object to another location. Pass the path of the new location.
CopyHere IDispatch* MoveHere([in] BSTR SourceName,
                               [in] BSTR NewName)
Same as MoveHere, but only copies the object.
Parent BSTR Parent() Returns the parent container to the current object.
GetObject IDispatch* GetObject([in] BSTR ClassName,                               [in] BSTR RelativeName) Used to set a local variable to an object; for example: Set objMem = AUOUser.GetObject("member", "robert").


Figure 6   UserProfile.asp


 <%
 Option Explicit
 
 ' *************************************************************
 ' TITLE:
 ' UserProfile.asp
 '
 ' PURPOSE:
 '   ASP page to get and put properties using the AUO object for
 '   personalization and membership by reading the values out of
 '   the DS based on cookie on user's computer.
 '
 ' HISTORY:
 '   4/23/98 Robert Howard
 '    Created
 ' *************************************************************
 On Error Resume Next
 
 ' ********************************
 ' Create some global variables
 ' ********************************
 Dim strAction           ' Display action of the page
 
 ' ********************************
 ' Create the AUOUser object
 ' ********************************
 Dim AUOUser            ' The AUO object
 
 Set AUOUser = Server.CreateObject("Membership.UserObjects.1")
 If Err.Number <> 0 Then
   Response.Write "Error: A fatal error has occurred, the AUO user "
   Response.Write "object was not successfully created."
   Response.End
 End If
 
 ' ********************************
 ' Include the following files:
 '   libDSUtils.inc
 ' ********************************
 %>
 <!--#Include File="libDSUtils.inc"-->
 
 <%
 ' ********************************
 ' If the form posted to itself
 ' process the form items
 If Request.Form("submit") <> "" Then
   ' Create the local variables
   ' ********************************
   Dim strUser                      ' User Name
   Dim strPW                        ' Password
   Dim strFirstName                 ' First Name
   Dim strLastName                  ' Last Name
 
   ' Read the variables from the form
   ' ********************************
   strUser           = Request.Form("cn")
   strPW             = Request.Form("userPassword")
   strFirstName      = Request.Form("givenName")
   strLastName       = Request.Form("sn")
 
   ' Are we moving a user or remembering
   ' a user that lost their cookie?
   ' ********************************
   If strUser <> "" Then
     ' Create some variables to navigate the DS
     ' ********************************
     Dim strRootPath          ' ADS Path to object
     Dim strOrgName           ' Name of the membership instance
     Dim nLoopServer          ' Variable used to identify the organization
     Dim objRoot              ' Root DS object
     Dim objMembersContainer  ' Members DS object
 
     ' Get the Root path to the DS
     strRootPath = GetDSRootPath()
                 
     ' Find o=, the following data is the
     ' organization name to build a path to
     ' a container if necessary
     ' ********************************
     nLoopServer = InStr(strRootPath, "o=")
     If nLoopServer > 0 Then
       strOrgName = Right(strRootPath, Len(strRootPath) - nLoopServer- 1)
     End If
 
     ' Get LDAP root Path as current User
     ' ********************************
     Set objRoot = AUOUser.GetObjectAsUser(strRootPath)
     If Err.Number <> 0 Then
       Response.Write "Unable to get LDAP root..."
       Response.End
     End If
 
     ' Get members container
     ' ********************************
     Set objMembersContainer = objRoot.GetObject("organizationalUnit", "ou=Members")
     If Err.Number <> 0 Then
       Response.Write "Unable to bind to members container"
       Response.End
     End If
 
     ' Attempt to get cn of new/existing user if this fails
     ' then we can move the anonymous user to the membership
     ' container with this user name
     ' ********************************
     Set AUOUser = objMembersContainer.GetObject("member", "cn=" & strUser)
     If AUOUser.userPassword <> strPW Then
       Response.Write "Bad username/password...the username you chose already exits..."
       Response.End
     ElseIf Err.Number <> 0 Then
       Err.Clear
 
       ' Move anonymous user to members container and set values
       ' ********************************
       objmembersContainer.moveHere AUOUser.ADsPath, "cn=" & strUser
       If Err.Number <> 0 Then
         Response.Write "Unable to move anonymous user"
         Response.End
       End If
 
       ' Set our AUO object to point to new correct object
       ' ********************************
       Set AUOUser = objmembersContainer.GetObject("member", "cn=" & strUser)
       If Err.Number <> 0 Then
         Response.Write "Unable to move get moved user"
         Response.End
       End If
 
       ' Call method to send cookies to the user
       ' ********************************
       SendCookiesToNewUser()
 
       ' Call method to add attributes to the user
       ' ********************************
       SetUserValues()
 
       ' Response
       ' ********************************
       strAction = "<BR><B>Action:</B> Binding as new user...<BR>"
     Else ' User exists bind to this user
       ' Call method to send cookies to the user
       ' ********************************
       SendCookiesToNewUser()
 
       ' Response
       ' ********************************
       strAction = "<BR><B>Action:</B> Binding as existing user...<BR>"
     End If
   Else
     ' Did this user complete the form?
     ' ********************************
     If AUOUser.userPassword <> "" Then
 
       ' Call method to add attributes to the user
       ' ********************************
       SetUserValues()
 
       ' Response
       ' ********************************
       strAction = "<BR><B>Action:</B> Set values for user...<BR>"
     Else
       strAction = "<BR><B>Error:</B> You must enter a username and password...<BR>"
     End If
   End If
 End If
 %>
 
 <HTML>
 <TITLE>UserProfile Demo</TITLE>
 <BODY BGCOLOR=#FFFFFF>
 
 <FONT SIZE=6 FACE="ARIAL">
 <B>
 User Profile
 </B>
 </FONT>
 <FONT FACE=ARIAL SIZE=2>
 <%=strAction%>
 </FONT>
 <HR SIZE=1>
 
 <%
 ' ********************************
 ' Check if we have a password.  If
 ' we do then the user is not
 ' anonymous; otherwise, let the user
 ' roll-up to a regular account
 ' ********************************
 Response.Write("<FONT FACE=ARIAL SIZE=2>")
 If AUOUser.userPassword <> "" Then
     Response.Write("Thank you for being a member.")
     Response.Write(" If you would like to see this page in action:")
     Response.Write("<LI> Bookmark this page.")
     Response.Write("<LI> Close your browser.")
     Response.Write("<LI> Delete your cookies.")
     Response.Write("<LI> Come back to this page and remember the user.")
     Response.Write("<P>or")
     Response.Write("<LI> Bookmark this page.")
     Response.Write("<LI> Close your browser.")
     Response.Write("<LI> Come back to this page and let the cookie id you.")
 Else
     Response.Write("Please complete the following form to become a member.")
     Response.Write("<P>")
     Response.Write("You may either enter:")
     Response.Write("<LI> An existing username and password to 'remember' a user")
     Response.Write("<LI> A new username and password to create a new user.")
 End If
 Response.Write("</FONT>")
 %>
 
 <HR SIZE=1>
 <FORM METHOD=POST>
 <TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0>
 
 <%
 If AUOUser.userPassword <> "" Then
 %>
 
     <!--First Name-->
     <TR>
         <TD ALIGN=LEFT>
             <FONT FACE="ARIAL" SIZE=2>
             <B>
             First Name:
             </B>
             </FONT>
         </TD>
 
         <TD WIDTH=5>
         </TD>
 
         <TD ALIGN=LEFT>
             <INPUT TYPE=TEXT NAME="givenName" VALUE="<%=AUOUser.givenName%>">
         </TD>
     </TR>
 
     <!--Last Name-->
     <TR>
         <TD ALIGN=LEFT>
             <FONT FACE="ARIAL" SIZE=2>
             <B>
             Last Name:
             </B>
             </FONT>
         </TD>
 
         <TD WIDTH=5>
         </TD>
 
         <TD ALIGN=LEFT>
             <INPUT TYPE=TEXT NAME="sn" VALUE="<%=AUOUser.sn%>">
         </TD>
     </TR>
 
 <%
 Else
 %>
     <!--User Name-->
     <TR>
         <TD ALIGN=LEFT>
             <FONT FACE="ARIAL" SIZE=2>
             <B>
             User Name:
             </B>
             </FONT>
         </TD>
 
         <TD WIDTH=5>
         </TD>
 
         <TD ALIGN=LEFT>
     <INPUT TYPE=TEXT NAME="cn">
         </TD>
     </TR>
 
     <!--Password-->
     <TR>
         <TD ALIGN=LEFT>
             <FONT FACE="ARIAL" SIZE=2>
             <B>
             Password:
             </B>
             </FONT>
         </TD>
 
         <TD WIDTH=5>
         </TD>
 
         <TD ALIGN=LEFT>
     <INPUT TYPE=PASSWORD NAME="userPassword">
         </TD>
     </TR>
 <%
 End If
 %>
     <!--Space-->
     <TR>
         <TD COLSPAN=3 HEIGHT=15>
             &nbsp;
         </TD>
     </TR>
 
     <!--Submit-->
     <TR>
         <TD ALIGN=LEFT>
         </TD>
 
         <TD WIDTH=5>
         </TD>
 
         <TD ALIGN=LEFT>
             <%
             ' Display the button based on the form
             If AUOUser.userPassword <> "" Then
               Response.Write ("<INPUT TYPE=SUBMIT NAME=SUBMIT VALUE=""Update 
                               Information"">")
             Else
               Response.Write ("<INPUT TYPE=SUBMIT NAME=SUBMIT VALUE=""Create / 
                               Remember User"">")
             End If
             %>
         </TD>
     </TR>
 </TABLE>
 </FORM>
 </HTML>
 
 <%
 ' *************************************************************
 ' FUNCTION: SetUserValues
 '
 ' PURPOSE:  Reads the values that the user passed via the Form, and sets
 '           the values in the DS as long as the item name corresponds to
 '           an item in the DS
 '
 ' PARAMETERS:
 '           None
 '
 ' HISTORY:  4/23/98 Robert Howard
 '           Created
 '    
 Public Function SetUserValues()
     On Error Resume Next
 
        ' Used to hold item from Request.Form collection
        ' ****************************
     Dim item
     
     ' Put values into the DS
     ' ****************************
     For Each item in Request.Form
                ' Don't put submit or cn
                ' ****************************
         If Item <> "SUBMIT" AND Item <> "cn" Then
             If Request.Form(item) <> "" Then
                 AUOUser.put cstr(item), cstr(Request.Form(item))
             Else
                 AUOUser.putEx 1, cstr(item), cstr(Request.Form(item))
             End If
         End If
     Next
 
     ' Call SetInfo
     ' ****************************
     AUOUser.SetInfo
 
     ' Handle any Errors
     ' ****************************
     If Err.Number <> 0 Then
         Response.Write "Error occurred while attempting to put information."
                Response.Write "<P>"
                Response.Write "Check that the Membership instance is mapped to the "
                Response.Write "correct virtual server."
                Response.End
     End If
 End Function
 %>

Figure 7   libDSUtils.inc


 <%
 ' ----------------------------------------------------------------------------
 ' libDSUtils.inc
 '
 ' Purpose:
 ' This file is a library of commonly used DS functions.
 '
 '
 
 ' Global Variable to hold the name of the server
 ' ****************************************************************************
 Dim g_strServerName
 
 
 ' ****************************************************************************
 ' GetDSRootPath
 ' 
 ' Purpose:
 '    Returns the root path in the DS using security context of current user
 '
 '
 ' ****************************************************************************
 
 
 Function GetDSRootPath
     On Error Resume Next
 
     ' Initialize return value
     GetDSRootPath = ""
 
     ' Declare variables
     Dim objRoot
     Dim strLDAPServerAndPort
 
     ' Call the function to return the ldap server
     ' and port number
     strLDAPServerAndPort = "LDAP://" & GetLdapServerAndPort()
 
     ' Get Root object
     Set objRoot = AUOUser.GetObjectAsUser(strLdapServerAndPort)
     If Err.Number <> 0 Then
         Response.Write "GetDSRootPath failed..."
         Err.Clear
         Exit Function
     End If
 
     ' Return Root path
     GetDSRootPath = objRoot.ADsPath
 
     Set objRoot = Nothing
 End Function
 
 
 
 
 ' ****************************************************************************
 ' GetLdapServerAndPort
 ' 
 ' Purpose:
 '    Returns the ldap server and port number to the caller
 '
 '
 ' ****************************************************************************
 
 Function GetLdapServerAndPort
     On Error Resume Next
 
     ' Create some local variables
     Dim nVirtualServer            ' Virtual Server instance number
     Dim objBrokServers
     Dim objBroker
     Dim lVirtBrokID
     Dim strComment
     Dim objLDAPConfig
     Dim strServer
 
     ' Determine the membership server that this virtual server instance is mapped to
     nVirtualServer = Request.ServerVariables("INSTANCE_ID")
 
     ' Create an instance of a Membership Admin Server object
     Set objBrokServers = CreateObject("MemAdmin.BrokServers")
     If Err.Number <> 0 Then
         Response.Write "Create MemAdmin.BrokServers failed"
         Err.Clear
         GetLdapServerAndPort = ""        ' Failed to create object
         Exit Function
     End If
 
     ' Connect to the server instance
     objBrokServers.MappedTo "W3SVC", nVirtualServer, lVirtBrokId, strComment
     If Err.Number <> 0 Then
         Response.Write "Mapping to virtual server failed..."
         Err.Clear
         GetLdapServerAndPort = ""        ' Server instance not mapped
         Exit Function
     End If
 
     ' User membership broker to determine LDAP server and PORT
     Set objBroker = CreateObject("MemAdmin.BrokConfig")
     If Err.Number <> 0 Then
         Response.Write "Creating MemAdmin.BrokConfig failed."
         Err.Clear
         GetLdapServerAndPort = ""        ' Failed to create object
         Exit Function
     End If
 
     objBroker.GetConfig(lVirtBrokID)
     If Err.Number <> 0 Then
         Response.Write "Getting membership server config failed."
         Err.Clear
         GetLdapServerAndPort = ""        ' Failed to get config
         Exit Function
     End If
 
     ' Get the server name
     g_strServerName = objBroker.bszServerName
 
     ' Should we do ssl to this server?
     If (objBroker.bSecure) then
         strServer = g_strServerName & ":" & objBroker.lSecurePort
     Else
         strServer = g_strServerName & ":" & objBroker.lPort
     End If
 
     ' Return info
     GetLdapServerAndPort = strServer
 End Function
 
 
 
 ' ****************************************************************************
 ' SendCookiesToNewUser
 ' 
 ' Purpose:
 '    Sends the user the cookies to id them
 '
 '
 ' ****************************************************************************
 
 Public Function SendCookiesToNewUser()
     On Error Resume Next
 
     Dim strVUGuid
     Dim strVUCn
 
 
     ' Retrieve User values
     ' ***********************************
     strVUGuid    = AUOUser.Get("GUID")
     strVUCn     = AUOUser.Get("cn")
 
 
     ' Remove decoration from GUID
     ' ***********************************
     strVUGuid = Replace(strVUGuid, "-", "")
     strVUGuid = Replace(strVUGuid, "{", "")
     strVUGuid = Replace(strVUGuid, "}", "")
 
 
     ' Send a cookie
     ' ***********************************
     Dim objNewCookie
     Set objNewCookie = Server.CreateObject("Membership.verifusr.1")
   
     If Err.Number <> 0 Then
       Response.Write "Unable to verify user."
       Err.Clear
     Else
 
       
       ' Everything looks good...set the cookies
       ' ***********************************
       objNewCookie.IssueCookie "SITESERVER", "GUID=" & strVUGuid
       objNewCookie.IssueCookie "MEMUSER", strVUCn
     End If
 
 
     ' Release VerifyUser Object
     ' ***********************************
     Set objNewCookie = Nothing
 End Function
 %>