共用方式為


ProfileMigrateEventHandler 代理人

定義

代表將處理 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

e
ProfileMigrateEventArgs

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)

取得表示特定委派所代表之方法的物件。

適用於

另請參閱