This documentation is archived and is not being maintained.

ProfileMigrateEventHandler Delegate

Represents the method that will handle the MigrateAnonymous event of the ProfileModule class.

Namespace:  System.Web.Profile
Assembly:  System.Web (in System.Web.dll)

Public Delegate Sub ProfileMigrateEventHandler ( _
	sender As Object, _
	e As ProfileMigrateEventArgs _


Type: System.Object
The ProfileModule that raised the MigrateAnonymous event.
Type: System.Web.Profile.ProfileMigrateEventArgs
A ProfileMigrateEventArgs that contains the event data.

The ProfileMigrateEventHandler delegate is defined for the MigrateAnonymous event of the ProfileModule class. You can access the MigrateAnonymous event of the ProfileModule class in the Global.asax file for your ASP.NET application as shown in the example for this topic.

You can use the MigrateAnonymous event to copy profile property values from an anonymous profile to an authenticated profile when someone who has been anonymously using your application logs in.

When an application that has the user profile enabled is started, ASP.NET creates a new class of type ProfileCommon, which inherits from the ProfileBase class. When the ProfileCommon class is generated, based on the profile properties specified in the Web.config file, a GetProfile method is added that enables you to retrieve a ProfileCommon object based on a user name. You can use the GetProfile method of the current profile to retrieve the property values of the anonymous profile. The anonymous property values can then be copied to the current profile for the authenticated user.

The following code examples show a Web.config file that enables anonymous authentication and the MigrateAnonymous event included in the Global.asax file for an ASP.NET application.

The following code example shows a Web.config file that enables anonymous identification and profile properties that support anonymous users.

    <authentication mode="Forms" >
      <forms loginUrl="login.aspx" name=".ASPXFORMSAUTH" />

    <anonymousIdentification enabled="true" />

    <profile enabled="true" defaultProvider="AspNetSqlProvider">
        <add name="ZipCode" allowAnonymous="true" />
        <add name="CityAndState" allowAnonymous="true" />
        <add name="StockSymbols" type="System.Collections.ArrayList" allowAnonymous="true" />

The following code example shows the MigrateAnonymous event included in the Global.asax file for an ASP.NET application. The MigrateAnonymous event copies profile property values from the anonymous profile to the profile for the current user.

Public Sub Profile_OnMigrateAnonymous(sender As Object, args As ProfileMigrateEventArgs)
  Dim anonymousProfile As ProfileCommon = Profile.GetProfile(args.AnonymousID)

  Profile.ZipCode = anonymousProfile.ZipCode
  Profile.CityAndState = anonymousProfile.CityAndState
  Profile.StockSymbols = anonymousProfile.StockSymbols

  ' Delete the anonymous profile. If the anonymous ID is not 
  ' needed in the rest of the site, remove the anonymous cookie.


  ' Delete the user row that was created for the anonymous user.
  Membership.DeleteUser(args.AnonymousID, True)
End Sub

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.