ProfileMigrateEventHandler 代理人
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
代表將處理 ProfileModule 類別的 MigrateAnonymous 事件之方法。
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)
參數
- sender
- Object
引發 ProfileModule 事件的 MigrateAnonymous。
ProfileMigrateEventArgs,其中包含事件資料。
範例
下列程式碼範例示範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
備註
委派 ProfileMigrateEventHandler 是針對 MigrateAnonymous 類別的 ProfileModule 事件所定義。 您可以在 ASP.NET 應用程式的 Global.asax 檔案中存取 MigrateAnonymous 類別的事件 ProfileModule ,如本主題的範例所示。
您可以使用 MigrateAnonymous 事件,將配置檔案屬性值從匿名配置檔案複製到已驗證的設定檔,當有人匿名使用您的應用程式登入時。
啟動已啟用使用者設定檔的應用程式時,ASP.NET 建立類型 ProfileCommon
的新類別,此類別繼承自 ProfileBase 類別。 ProfileCommon
當產生 類別時,會根據Web.config檔案 GetProfile
中指定的配置檔案屬性,新增方法可讓您根據使用者名稱擷取 ProfileCommon
物件。 您可以使用 GetProfile
目前設定檔的 方法來擷取匿名設定檔的屬性值。 然後,可以將匿名屬性值複製到已驗證使用者的目前設定檔。
擴充方法
GetMethodInfo(Delegate) |
取得表示特定委派所代表之方法的物件。 |
適用於
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應