gpt4 book ai didi

c# - asp.net 如何在一段时间后自动清除购物车

转载 作者:太空宇宙 更新时间:2023-11-03 13:33:35 25 4
gpt4 key购买 nike

我创建了一个电子商务网站。我的问题是,如果用户在将商品添加到购物车后离开网站,无论他是否登录,我都想在一段时间后自行清除购物车。

我的 Global.ascx 代码是:

void Profile_OnMigrateAnonymous(object sender, ProfileMigrateEventArgs e)
{
ProfileCommon anonymousProfile = Profile.GetProfile(e.AnonymousID);
if (anonymousProfile.SCart != null)
{
if (Profile.SCart == null)
Profile.SCart = new ShoppingCartExample.Cart();

Profile.SCart.Items.AddRange(anonymousProfile.SCart.Items);

anonymousProfile.SCart = null;
}

ProfileManager.DeleteProfile(e.AnonymousID);
AnonymousIdentificationModule.ClearAnonymousIdentifier();
}

但我不知道该怎么做。请帮我。谢谢。

最佳答案

您可以使用 System.Web.Caching.Cache缓存购物车。您可以使用绝对或滑动过期来控制购物车在缓存中的时间段。

有了缓存,只获取购物车,如果返回null,缓存已经过期(意味着清除购物车)。

关于c# - asp.net 如何在一段时间后自动清除购物车,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19535163/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com