How To Programmatically Switch Between Anonymous Cookie and Forms Authentication (263964)



The information in this article applies to:

  • Microsoft Site Server 3.0
  • Microsoft Site Server 3.0 Commerce Edition

This article was previously published under Q263964

SUMMARY

A common issue that many Site Server administrators face is how to switch between Anonymous Cookie Authentication and Forms Authentication.

MORE INFORMATION

A Web site may allow access to both anonymous and registered users, and provide ways for the anonymous users to configure and save their preferences. When the anonymous user becomes a registered user, the Web administrator needs to transfer the preferences in the anonymous user profile to the registered user profile.

The code below demonstrates how you can programmatically migrate the anonymous user profile to the members container.
Sub MoveMember(byval strUserID)
         Dim oParent
         Dim oContainer
         Dim oCookie
         Dim oAUO	
         Dim sGIUD

	On Error Resume Next
         sGUID = Request.Cookies("SITESERVER")("GUID")
	' Check if cookie has GUID.
	if sGUID <> "" Then
		'
		' Get the parent object.
		Set oParent = oAUO.GetObjectAsUser(objAUO.Parent)
		'
		' Get the grandparent object.
		Set oContainer = oAUO.GetObjectAsUser(oParent.Parent)
		'
		'Move the object to the target container.
		oContainer.MoveHere  oAUO.ADsPath, "cn=" & strUserID

		' Create the cookie object.
		Set oCookie = Server.CreateObject("Membership.verifusr.1")
		' Issue cookie to the old user.
		oCookie.IssueCookieToOldUser(cstr(strUserID))
	End if
End Sub
				

Modification Type:MinorLast Reviewed:7/2/2004
Keywords:kbhowto KB263964