ProfileModule.MigrateAnonymous Evento

Definizione

Si verifica quando l'utente anonimo per un profilo accede.

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 evento

Esempio

Nell'esempio seguente viene illustrato un file di Web.config che consente l'identificazione anonima e le proprietà del profilo che supportano gli utenti anonimi.

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

Nell'esempio di codice seguente viene illustrato l'evento MigrateAnonymous incluso nel file Global.asax per un'applicazione ASP.NET. L'evento MigrateAnonymous copia i valori delle proprietà del profilo dal profilo anonimo al profilo per l'utente corrente.

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

Commenti

È possibile accedere all'evento MigrateAnonymous della classe ProfileModule nel file Global.asax per l'applicazione ASP.NET usando l'evento globale Profile_MigrateAnonymous, come illustrato nell'esempio per questo argomento.

È possibile usare l'evento per copiare i MigrateAnonymous valori delle proprietà del profilo da un profilo anonimo a un profilo autenticato quando un utente che usa in modo anonimo l'applicazione accede.

Quando viene avviata un'applicazione con il profilo utente abilitato, ASP.NET crea una nuova classe di tipo ProfileCommon, che eredita dalla ProfileBase classe . Le funzioni di accesso fortemente tipate vengono aggiunte alla ProfileCommon classe per ogni proprietà definita nella sezione di configurazione del <profilo> . Un GetProfile metodo consente di recuperare un ProfileCommon oggetto in base a un nome utente. È possibile utilizzare il GetProfile metodo del profilo autenticato corrente per recuperare i valori delle proprietà del profilo anonimo. I valori delle proprietà anonime possono quindi essere copiati nel profilo corrente per l'utente autenticato.

Si applica a

Vedi anche