ProfileMigrateEventHandler 委托

定义

表示将处理 ProfileModule 类的 MigrateAnonymous 事件的方法。Represents the method that will handle the MigrateAnonymous event of the ProfileModule class.

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 事件的 MigrateAnonymousThe ProfileModule that raised the MigrateAnonymous event.

e
ProfileMigrateEventArgs

包含事件数据的 ProfileMigrateEventArgsA ProfileMigrateEventArgs that contains the event data.

继承
ProfileMigrateEventHandler

示例

下面的代码示例演示一个 web.config 文件, 该文件启用匿名身份验证, MigrateAnonymous并在 ASP.NET 应用程序的 global.asax 文件中包含该事件。The following code examples show a Web.config file that enables anonymous authentication and the MigrateAnonymous event included in the Global.asax file for an ASP.NET application.

下面的代码示例演示一个 web.config 文件, 该文件启用支持匿名用户的匿名标识和配置文件属性。The following code example shows a Web.config file that enables anonymous identification and profile properties that support anonymous users.

<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>  

下面的代码示例演示 ASP.NET MigrateAnonymous应用程序的 global.asax 文件中包含的事件。The following code example shows the MigrateAnonymous event included in the Global.asax file for an ASP.NET application. MigrateAnonymous事件将配置文件属性值从匿名配置文件复制到当前用户的配置文件。The MigrateAnonymous event copies profile property values from the anonymous profile to the profile for the current user.

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

注解

委托是ProfileModule MigrateAnonymous为类的事件定义的。 ProfileMigrateEventHandlerThe ProfileMigrateEventHandler delegate is defined for the MigrateAnonymous event of the ProfileModule class. 如本主题的MigrateAnonymous示例中所ProfileModule示, 可以访问 ASP.NET 应用程序的 global.asax 文件中的类的事件。You can access the MigrateAnonymous event of the ProfileModule class in the Global.asax file for your ASP.NET application as shown in the example for this topic.

当使用你的MigrateAnonymous应用程序登录的人员匿名使用时, 你可以使用事件将配置文件属性值从匿名配置文件复制到经过身份验证的配置文件。You can use the MigrateAnonymous event to copy profile property values from an anonymous profile to an authenticated profile when someone who has been anonymously using your application logs in.

当已启用用户配置文件的应用程序启动时, ASP.NET 将创建一个类型ProfileCommon为的新类, 该类继承ProfileBase自类。When an application that has the user profile enabled is started, ASP.NET creates a new class of type ProfileCommon, which inherits from the ProfileBase class. 根据 web.config 文件中指定的配置文件属性生成GetProfile ProfileCommon 类时,将添加一个方法,该方法使你能够根据ProfileCommon用户名检索对象。When the ProfileCommon class is generated, based on the profile properties specified in the Web.config file, a GetProfile method is added that enables you to retrieve a ProfileCommon object based on a user name. 您可以使用GetProfile当前配置文件的方法检索匿名配置文件的属性值。You can use the GetProfile method of the current profile to retrieve the property values of the anonymous profile. 然后, 可以将匿名属性值复制到经过身份验证的用户的当前配置文件。The anonymous property values can then be copied to the current profile for the authenticated user.

扩展方法

GetMethodInfo(Delegate)

获取指示指定委托表示的方法的对象。Gets an object that represents the method represented by the specified delegate.

适用于

另请参阅