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

示例

以下代码示例演示一个 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的新类,该类继承自 类 ProfileBaseProfileCommon生成 类时,根据 Web.config 文件中指定的配置文件属性,将添加一个GetProfile方法,使你能够基于用户名检索ProfileCommon对象。 可以使用 GetProfile 当前配置文件的 方法来检索匿名配置文件的属性值。 然后,可以将匿名属性值复制到经过身份验证的用户的当前配置文件。

扩展方法

GetMethodInfo(Delegate)

获取指示指定委托表示的方法的对象。

适用于

另请参阅