MigrateAnonymous

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

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

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

 

下面的示例演示一个 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>
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);
            }
            

 

 备注

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

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

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

posted @ 2008-11-07 10:57  烂仔  阅读(410)  评论(0编辑  收藏  举报