ProfileModule.MigrateAnonymous 事件

定義

當設定檔的匿名使用者登入時發生。

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 

事件類型

範例

下列範例顯示Web.config檔案,可啟用支援匿名使用者的匿名識別和配置檔案屬性。

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

下列程式碼範例顯示 MigrateAnonymous ASP.NET 應用程式之 Global.asax 檔案中包含的事件。 事件會將 MigrateAnonymous 配置檔案屬性值從匿名配置檔案複製到目前使用者的設定檔。

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

備註

您可以使用全域事件來存取 MigrateAnonymous ASP.NET 應用程式的 Profile_MigrateAnonymous Global.asax 檔案中 類別的事件 ProfileModule ,如本主題的範例所示。

當使用應用程式登入的使用者已匿名登入時,您可以使用 MigrateAnonymous 事件,將配置檔案屬性值從匿名配置檔案複製到已驗證的設定檔。

啟動已啟用使用者設定檔的應用程式時,ASP.NET 會建立 類型的新類別 ProfileCommon ,其繼承自 ProfileBase 類別。 強型別存取子會針對設定檔 > 組態區段中定義的 < 每個屬性新增至 ProfileCommon 類別。 方法 GetProfile 可讓您根據使用者名稱擷取 ProfileCommon 物件。 您可以使用 GetProfile 目前已驗證設定檔的 方法來擷取匿名設定檔的屬性值。 然後,匿名屬性值可以複製到已驗證使用者的目前設定檔。

適用於

另請參閱