ProfileModule.MigrateAnonymous Evento
Definizione
Viene generato quando l'utente anonimo relativo a un profilo effettua l'accesso.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
Esempi
Nell'esempio seguente viene illustrato un file Web. config che consente l'identificazione anonima e le proprietà del profilo che supportano utenti anonimi.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>
Nell'esempio di codice riportato di MigrateAnonymous seguito viene illustrato l'evento incluso nel file Global. asax per un'applicazione ASP.NET.The following code example shows the MigrateAnonymous event included in the Global.asax file for an ASP.NET application. L' MigrateAnonymous evento copia i valori delle proprietà del profilo dal profilo anonimo al profilo per l'utente corrente.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
Commenti
È possibile accedere all' MigrateAnonymous evento ProfileModule della classe nel file Global. asax per l'applicazione ASP.NET usando l' Profile_MigrateAnonymous
evento globale, come illustrato nell'esempio di questo argomento.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.
È possibile usare l' MigrateAnonymous evento per copiare i valori delle proprietà del profilo da un profilo anonimo a un profilo autenticato quando un utente che è stato usato in modo anonimo per l'accesso all'applicazione.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.
Quando viene avviata un'applicazione con il profilo utente abilitato, ASP.NET crea una nuova classe di tipo ProfileCommon
, che eredita ProfileBase dalla classe.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. Le ProfileCommon
funzioni di accesso fortemente tipizzate vengono aggiunte alla classe per ogni proprietà definita nella sezione di configurazione.Strongly typed accessors are added to the ProfileCommon
class for each property defined in the configuration section. Un GetProfile
metodo consente di recuperare un ProfileCommon
oggetto basato su un nome utente.A GetProfile
method enables you to retrieve a ProfileCommon
object based on a user name. È possibile utilizzare il GetProfile
metodo del profilo autenticato corrente per recuperare i valori delle proprietà del profilo anonimo.You can use the GetProfile
method of the current, authenticated profile to retrieve the property values of the anonymous profile. I valori delle proprietà anonime possono quindi essere copiati nel profilo corrente per l'utente autenticato.The anonymous property values can then be copied to the current profile for the authenticated user.