在Global.asax文件中,增加一个方法:
protected void Profile_MigrateAnonymous(Object s, ProfileMigrateEventArgs e)
{
ProfileCommon anonProfile = Profile.GetProfile(e.AnonymousID);
//迁移Profile用户名
//Profile.userName = anonProfile.userName;
//迁移购物车
//Profile.ShoppingCart = anonProfile.ShoppingCart;
IEnumerator ie = anonProfile.ShoppingCart.CartItems.GetEnumerator();
while (ie.MoveNext())
{
Profile.ShoppingCart.AddCartItem((CartItem)ie.Current);
}
//清除匿名COOKIE,不然每次请求页面都执行此事件
AnonymousIdentificationModule.ClearAnonymousIdentifier();
// Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(-1);
//匿名COOKIE标识已重置,下次匿名访问将创建新的profile数据条,原来的匿名profile数据条已无意义
ProfileManager.DeleteProfile(e.AnonymousID);
}
本文介绍了一个在Global.asax文件中实现的匿名用户资料迁移过程。该过程包括迁移用户名、购物车信息,清除匿名Cookie,并删除旧的匿名用户资料。
31

被折叠的 条评论
为什么被折叠?



