ProfileMigrateEventArgs.AnonymousID 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得匿名檔案的匿名識別碼,從中遷移檔案的房產價值。
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 Global.asax 檔案中包含的事件,適用於 ASP.NET 應用程式
以下程式碼範例展示了一個 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 Global.asax 檔案中包含的事件,用於一個 ASP.NET 應用程式。 事件會 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 目前設定檔的方法來取得匿名設定檔的屬性值。 匿名屬性值可複製至已認證使用者的當前設定檔。 請參見第二個程式碼範例,了解如何複製匿名屬性值。