Previous in Contents Next in Contents

Setting a User's Attributes

The following example demonstrates how to go about adding information about a user into a directory service in an ASP script. This example demonstrates working with both single and multivalue attributes.

 Example 1

The first example updates a user's attribute in the directory service specified by the default AUO entry. For this example, assume the schema definition for "objects" of type "member" has an attribute called "FavoriteColor." Assume further that the default AUO provider has the named value Class equal to "member" and the appropriate ADsPathPrefix named value contains a valid ADSI path prefix to a container "object" of objects of class "member." You could then proceed as follows:

<% 
   ' Create the UserObjects object.  We use the built-in Server "object"
   ' or dispinterface to create the object.  This automatically 
   ' innitializes the UserObjects object with the IIS server instance
   ' and the requesting user's username

   Set IUserObjects = Server.CreateObject("Membership.UserObjects")
   
   ' set the target attribute name
   Attribute1 = "FavoriteColors"

   ' Here we build an array of values to be put in a multivalue attribute
   dim usArray
   usArray = Array("blue","green","voilet","orange")

   ' define these ADSI related values here so they have "English"
   ' descriptions
   const ADS_PROP_ERASE = 1
   const ADS_PROP_UPDATE = 2
   const ADS_PROP_APPEND = 3
   '  Update the attribute for the current user
   IUserObject.PutEx ADS_PROP_UPDATE, Attribute1, (usArray)
%>

You could use the Put method here instead of PutEx. Most ADSI implementations allow setting multivalue attributes with Put. However, more functionality is exposed for the PutEx method, such as erasing as well as appending data to the user's attribute. It simply requires one extra argument.


© 1997-2000 Microsoft Corporation. All rights reserved.