ProfileMigrateEventHandler Delegat

Definicja

Reprezentuje metodę, która obsłuży MigrateAnonymous zdarzenie ProfileModule klasy.

public delegate void ProfileMigrateEventHandler(System::Object ^ sender, ProfileMigrateEventArgs ^ e);
public delegate void ProfileMigrateEventHandler(object sender, ProfileMigrateEventArgs e);
type ProfileMigrateEventHandler = delegate of obj * ProfileMigrateEventArgs -> unit
Public Delegate Sub ProfileMigrateEventHandler(sender As Object, e As ProfileMigrateEventArgs)

Parametry

sender
Object

To ProfileModule wywołało MigrateAnonymous zdarzenie.

e
ProfileMigrateEventArgs

Element ProfileMigrateEventArgs zawierający dane zdarzenia.

Przykłady

W poniższych przykładach kodu przedstawiono plik Web.config, który umożliwia uwierzytelnianie anonimowe i MigrateAnonymous zdarzenie zawarte w pliku Global.asax dla aplikacji ASP.NET.

Poniższy przykład kodu przedstawia plik Web.config, który umożliwia anonimową identyfikację i właściwości profilu, które obsługują anonimowych użytkowników.

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

Poniższy przykład kodu przedstawia MigrateAnonymous zdarzenie zawarte w pliku Global.asax dla aplikacji ASP.NET. Zdarzenie MigrateAnonymous kopiuje wartości właściwości profilu z profilu anonimowego do profilu bieżącego użytkownika.

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

Uwagi

Delegat ProfileMigrateEventHandler jest definiowany MigrateAnonymous dla zdarzenia ProfileModule klasy. Możesz uzyskać dostęp do MigrateAnonymous zdarzenia ProfileModule klasy w pliku Global.asax dla aplikacji ASP.NET, jak pokazano w przykładzie dla tego tematu.

Zdarzenie służy do kopiowania MigrateAnonymous wartości właściwości profilu z profilu anonimowego do profilu uwierzytelnionego, gdy ktoś anonimowo loguje się do aplikacji.

Po uruchomieniu aplikacji z włączonym profilem użytkownika ASP.NET tworzy nową klasę typu ProfileCommon, która dziedziczy z ProfileBase klasy. Po wygenerowaniu ProfileCommon klasy na podstawie właściwości profilu określonych w pliku Web.config zostanie dodana metoda umożliwiająca GetProfile pobranie ProfileCommon obiektu na podstawie nazwy użytkownika. Możesz użyć GetProfile metody bieżącego profilu, aby pobrać wartości właściwości profilu anonimowego. Wartości właściwości anonimowych można następnie skopiować do bieżącego profilu uwierzytelnionego użytkownika.

Metody rozszerzania

GetMethodInfo(Delegate)

Pobiera obiekt reprezentujący metodę reprezentowaną przez określonego delegata.

Dotyczy

Zobacz też