ProfileModule.MigrateAnonymous Evento

Definición

Se produce cuando el usuario anónimo para un perfil inicia sesión.

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 

Tipo de evento

Ejemplos

En el ejemplo siguiente se muestra un archivo Web.config que permite la identificación anónima y las propiedades de perfil que admiten usuarios anónimos.

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

En el ejemplo de código siguiente se muestra el MigrateAnonymous evento incluido en el archivo Global.asax para una aplicación de ASP.NET. El MigrateAnonymous evento copia los valores de propiedad de perfil del perfil anónimo en el perfil del usuario actual.

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

Comentarios

Puede acceder al MigrateAnonymous evento de la ProfileModule clase en el archivo Global.asax de la aplicación ASP.NET mediante el Profile_MigrateAnonymous evento global, como se muestra en el ejemplo de este tema.

Puede usar el MigrateAnonymous evento para copiar valores de propiedad de perfil de un perfil anónimo en un perfil autenticado cuando un usuario que ha estado anónimo con los registros de la aplicación.

Cuando se inicia una aplicación que tiene habilitado el perfil de usuario, ASP.NET crea una nueva clase de tipo ProfileCommon, que hereda de la ProfileBase clase . Los descriptores de acceso fuertemente tipados se agregan a la ProfileCommon clase para cada propiedad definida en la sección de configuración del <perfil> . Un GetProfile método permite recuperar un ProfileCommon objeto basado en un nombre de usuario. Puede usar el GetProfile método del perfil autenticado actual para recuperar los valores de propiedad del perfil anónimo. Los valores de propiedad anónima se pueden copiar en el perfil actual para el usuario autenticado.

Se aplica a

Consulte también