实现Profile购物车的匿名用户迁移

来源:互联网 发布:电脑闹钟提醒软件 编辑:程序博客网 时间:2024/06/05 18:40

实现Profile购物车的匿名用户迁移

IE

在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); 
}

原创粉丝点击