Microsoft KB Archive/279720

= How to Migrate Anonymous Cookie Authenticated Member to Members Container =

Article ID: 279720

Article Last Modified on 6/12/2001

-

APPLIES TO


 * Microsoft Site Server 3.0 Standard Edition

-



This article was previously published under Q279720



SUMMARY
The sample Microsoft ASP code in the &quot;More Information&quot; section of this article demonstrates how to move a user who is authenticated with Anonymous Cookie authentication from the AnonymousUsers container to the Members container of a Microsoft Site Server Personalization and Membership (P&M) LDAP store.



MORE INFORMATION
This example in this article assumes that the Microsoft IIS server instance that contains these files is mapped to a P&M LDAP instance and set for Automatic Cookie Membership authentication.

NOTE: Welcome.asp should be set for HTML Forms authentication. Logon.asp requires that an appropriate administrator name and password are entered for the adminname and adminpass variables.

After you copy the following files into the root directory of the Web server, browse to Logon.asp. To verify that the AnonymousUser is successfully moved to the Members container, start the Membership Directory Manager MMC interface, open the ou=AnonymousUsers,ou=Members container, and then verify that an anonymous user is created when you initially browse to the Logon.asp page. After you submit the contents of the form on the Logon.asp page, view the ou=Members container to verify that the user has been migrated with the appropriate user name.

Contents of Logon.asp:   Personalized Form   Register New Member or Change Registration info:     <% Dim objAUO Dim strTemp Dim item Dim errorlevel Dim adminname Dim adminpass

adminname = &quot;administrator&quot; adminpass = &quot;password&quot; errorlevel = &quot;&quot;

Const ADS_PROP_ERASE = 1 Const E_ADS_PROPERTY_NOT_FOUND = &H8000500D

' Create the Active User Object ' ***************************** Set objAUO = Server.CreateObject(&quot;Membership.UserObjects.1&quot;) If Err.Number <> 0 Then Response.Write &quot;Error: Can’t create the AUO&quot; Response.Write &quot;Suggestion: Make sure the IIS web is mapped &quot; Response.Write &quot;to a Membership Directory&quot; Response.End End If

' Has the forms collection been ' populated? ' ***************************** If Request.Form(&quot;SUBMIT&quot;) <> &quot;&quot; Then ' Enumerate through Request.Form ' ***************************** For Each item in Request.Form ' Ignore submit values ' *****************************   If Not LCase(item) = &quot;submit&quot; Then ' If the item has data ' *****************************     If Len(Request.Form(item)) <> 0 Then 'stop objAUO.Put CStr(item), CStr(Request.Form(item)) Else ' If the item has no data ' *****************************       If Len(objAUO.Get(CStr(item))) <> 0 Then ' Or the property doesn't exist yet ' *****************************         If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then Err.Clear Else ' No data to set, but the property ' exists, remove it           ' ***************************** objAUO.PutEx ADS_PROP_ERASE, CStr(item), &quot;&quot; End If       End If      End If    End If  Next ' Handle errors / SetInfo ' ***************************** If Err.Number <> 0 Then Response.Write &quot;Error: Problem occured while putting data&quot; & &quot;&quot; response.write &quot;Error number is: 0x&quot; & hex(err.number) & &quot;<BR>&quot; Response.Write &quot;Error description is: &quot; & err.description & &quot;<BR>&quot; response.write &quot;Look up this error number on &quot; & &quot;<A HREF=/kb/242076/en-us>http://support.microsoft.com/support/kb/articles/Q242/0/76.ASP</A>&quot; Response.End Else objAUO.SetInfo strNewMember = objAUO.givenname errorlevel = MigrateUser(objAUO, strNewMember, adminname, adminpass) End if if errorlevel = &quot;anonfail&quot; then Response.Write &quot;Please choose a different username, this name already exists in the membership directory&quot; else Response.Redirect (&quot;http://&quot; & Request.ServerVariables(&quot;SERVER_NAME&quot;) & &quot;/pmsamples/welcome.asp&quot;) end if end if %> <FORM METHOD=POST> </FORM> </BODY> </HTML>

Contents of Migrateuser.inc: <% Const L_InvalidParams = &quot;Invalid parameters&quot; Const L_GetParentFAIL = &quot;Cannot get the parent object of the user&quot; Const L_GetGrandParentFAIL = &quot;Cannot get the grandparent object of the user&quot; Const L_MoveHereFAIL = &quot;MoveHere failed&quot; Const L_VerifusrFAIL = &quot;Server.CreateObject failed for Membership.verifusr&quot; Const L_IssueOldCookieFAIL = &quot;IssueOldCookiesToNewUser Failed&quot; Const L_MoveAnonymousFAIL = &quot;anonfail&quot; ' ************************************************************************* ' Function name :  MigrateUser ' Sypnosis     :   Migrates anonymous user to registered user ' Parameters   :   oUserObject : Membership object to be moved '                  UserName : New name of account to use '                  ScriptID : ID used to bind to DS '                   ScriptPassword : Password used to bind to DS ' Returns       :   Empty string if no error, error message otherwise ' ************************************************************************* Function MigrateUser(oUserObject, UserName, ScriptID, ScriptPassword) On Error Resume Next '   'Check if parameters are valid if not IsObject(oUserObject) or UserName = &quot;&quot; or ScriptID = &quot;&quot; or ScriptPassword = &quot;&quot; Then MigrateUser = &quot;MigrateUser : &quot; & L_InvalidParams Exit Function End if   ' ' Check if cookie has GUID if Request.Cookies(&quot;SITESERVER&quot;)(&quot;GUID&quot;) <> &quot;&quot; Then if right(oUserObject.GetObjectAsUser(objAUO.Parent).adspath,14) = &quot;AnonymousUsers&quot; then '           ' Get the parent object Set ParentUserObject = oUserObject.GetObjectAsUser(oUserObject.Parent) if Err <> 0 Then MigrateUser = &quot;MigrateUser : &quot; & L_GetParentFAIL Exit Function End if           ' ' Get the grandparent object Set TargetContainer = oUserObject.GetObjectAsUser(ParentUserObject.Parent) if Err <> 0 Then MigrateUser = &quot;MigrateUser : &quot; & L_GetGrandParentFAIL Exit Function End if           ' 'Move the object to the target container TargetContainer.MoveHere oUserObject.ADsPath, &quot;cn=&quot; & UserName if Err <> 0 Then MigrateUser = &quot;L_MoveAnonymousFAIL&quot; Exit Function End if       else Set TargetContainer = oUserObject.GetObjectAsUser(oUserObject.Parent) 'Move the object to the target container TargetContainer.MoveHere oUserObject.ADsPath, &quot;cn=&quot; & UserName if Err <> 0 Then MigrateUser = &quot;MigrateUser : &quot; & L_MoveHereFAIL Exit Function End if       End if        ' ' create cookie object Set NewCookie = Server.CreateObject(&quot;Membership.verifusr&quot;) if Err <> 0 Then MigrateUser = &quot;MigrateUser : &quot; & L_VerifusrFAIL Exit Function End if       ' ' Issue cookie to the old user NewCookie.IssueCookieToOldUser(cstr(UserName)) if Err <> 0 Then MigrateUser = &quot;MigrateUser : &quot; & L_IssueCookieOldFAILED Exit Function End if   End if End Function %>

Contents of Welcome.asp: <HTML> <HEAD> <META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;> Welcome</TITLE> </HEAD> <%Set objAUO = Server.CreateObject(&quot;Membership.UserObjects.1&quot;)%> <BODY> <%response.write &quot;Welcome &quot; & objAUO.givenName & &quot;!&quot; & &quot;<BR>&quot;%> <%response.write &quot;Your password is: &quot; & objAUO.userPassword%> <P>&#xa0;</P> </BODY> </HTML>

Keywords: kbbug kbfix KB279720

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.