ProfileMigrateEventArgs.AnonymousID 属性

定义

获取从中迁移配置文件属性值的匿名配置文件的匿名标识符。

public:
 property System::String ^ AnonymousID { System::String ^ get(); };
public string AnonymousID { get; }
member this.AnonymousID : string
Public ReadOnly Property AnonymousID As String

属性值

从中迁移配置文件属性值的匿名配置文件的匿名标识符。

示例

下面的代码示例演示一个启用匿名身份验证的 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

注解

属性 AnonymousID 包含匿名用户的唯一标识符。 当使用应用程序的用户匿名登录时,你可以处理 MigrateAnonymous 事件,将用户的匿名配置文件中的配置文件属性值复制到其经过身份验证的配置文件。

启动启用了用户配置文件的应用程序时,ASP.NET 会创建类型 ProfileCommon为 的新类,该类继承自 ProfileBase 类,并包括Web.config文件中指定的配置文件属性。 ProfileCommon生成 类时,将添加一个GetProfile方法,使你能够基于用户名检索ProfileCommon对象。 可以使用 GetProfile 当前配置文件的 方法来检索匿名配置文件的属性值。 然后,可以将匿名属性值复制到经过身份验证的用户的当前配置文件。 有关复制匿名属性值的示例,请参阅第二个代码示例。

适用于

另请参阅