ProfileModule.MigrateAnonymous 事件

定义

当配置文件的匿名用户登录时发生。

public:
 event System::Web::Profile::ProfileMigrateEventHandler ^ MigrateAnonymous;
public event System.Web.Profile.ProfileMigrateEventHandler MigrateAnonymous;
member this.MigrateAnonymous : System.Web.Profile.ProfileMigrateEventHandler 
Public Custom Event MigrateAnonymous As ProfileMigrateEventHandler 

事件类型

示例

以下示例演示一个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

注解

可以使用全局 MigrateAnonymous 事件 ProfileModule 在 ASP.NET 应用程序的 Profile_MigrateAnonymous Global.asax 文件中访问 类的事件,如本主题的示例所示。

当匿名使用应用程序的用户登录时, MigrateAnonymous 可以使用 事件将配置文件属性值从匿名配置文件复制到经过身份验证的配置文件。

启动启用了用户配置文件的应用程序时,ASP.NET 会创建类型为 ProfileCommon的新类,该类继承自 类 ProfileBase 。 强类型访问器将添加到ProfileCommon配置文件>配置节中定义的每个属性的 <类中。 使用 GetProfile 方法可以根据用户名检索 ProfileCommon 对象。 可以使用 GetProfile 当前经过身份验证的配置文件的 方法来检索匿名配置文件的属性值。 然后,可以将匿名属性值复制到经过身份验证的用户的当前配置文件。

适用于

另请参阅