ProfileModule.MigrateAnonymous Event

Definition

Occurs when the anonymous user for a profile logs in.

public:
 event System::Web::Profile::ProfileMigrateEventHandler ^ MigrateAnonymous;
public event System.Web.Profile.ProfileMigrateEventHandler MigrateAnonymous;
member this.MigrateAnonymous : System.Web.Profile.ProfileMigrateEventHandler 
Public Custom Event MigrateAnonymous As ProfileMigrateEventHandler 

Event Type

Examples

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

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

    <anonymousIdentification enabled="true" />  

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

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 void Profile_OnMigrateAnonymous(object sender, ProfileMigrateEventArgs args)
{
  ProfileCommon anonymousProfile = 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.

  ProfileManager.DeleteProfile(args.AnonymousID);
  AnonymousIdentificationModule.ClearAnonymousIdentifier(); 

  // Delete the user row that was created for the anonymous user.
  Membership.DeleteUser(args.AnonymousID, true);

}
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.

  ProfileManager.DeleteProfile(args.AnonymousID)
  AnonymousIdentificationModule.ClearAnonymousIdentifier()

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

Remarks

You can access the MigrateAnonymous event of the ProfileModule class in the Global.asax file for your ASP.NET application by using the Profile_MigrateAnonymous global event, 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 a user 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. Strongly typed accessors are added to the ProfileCommon class for each property defined in the <profile> configuration section. A GetProfile method enables you to retrieve a ProfileCommon object based on a user name. You can use the GetProfile method of the current, authenticated 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.

Applies to

See also