ProfileMigrateEventArgs.AnonymousID 屬性

定義

取得匿名設定檔的匿名識別項,以從該設定檔移轉設定檔屬性值。

public:
 property System::String ^ AnonymousID { System::String ^ get(); };
public string AnonymousID { get; }
member this.AnonymousID : string
Public ReadOnly Property AnonymousID As String

屬性值

匿名設定檔的匿名識別項,以從該設定檔移轉設定檔屬性值。

範例

下列程式碼範例示範Web.config檔案,可啟用匿名驗證,以及 MigrateAnonymous ASP.NET 應用程式 Global.asax 檔案中包含的事件

下列程式碼範例顯示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

備註

屬性 AnonymousID 包含匿名使用者的唯一識別碼。 當有人匿名登入您的應用程式時,您可以處理 MigrateAnonymous 事件,將配置檔案屬性值從使用者的匿名配置檔案複製到其已驗證的設定檔。

啟動已啟用使用者設定檔的應用程式時,ASP.NET 會建立 類型的 ProfileCommon 新類別,該類別繼承自 ProfileBase 類別,並包含Web.config檔案中指定的配置檔案屬性。 ProfileCommon產生 類別時, GetProfile 會新增方法,讓您根據使用者名稱擷取 ProfileCommon 物件。 您可以使用 GetProfile 目前設定檔的 方法來擷取匿名設定檔的屬性值。 然後,可以將匿名屬性值複製到已驗證使用者的目前設定檔。 如需複製匿名屬性值的範例,請參閱第二個程式碼範例。

適用於

另請參閱