简体   繁体   English

在一定时间后如何在asp.net中自动清除购物车

[英]How to clear shopping cart automatically after a certain period in asp.net

I have created a e-commerece site. 我创建了一个电子商务网站。 my problm is that i want to clear shopping cart by itself after a certion period if user left the site after adding the items in cart either he is logged in or not. 我的问题是,如果用户在登录或未登录后将商品添加到购物车中之后离开站点,我想在一个确定的时期后自行清除购物车。

My Global.ascx code is: 我的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();
}

but i dont know that how to do this . 但我不知道该怎么做。 please help me. 请帮我。 Thanks. 谢谢。

You can use System.Web.Caching.Cache to cache the shoping cart. 您可以使用System.Web.Caching.Cache来缓存购物车。 You can use Absolute or Sliding expiration to control the time period the cart is in cache. 您可以使用绝对或滑动到期来控制购物车在缓存中的时间段。

With cache, just retrieve the cart, if return null, cache has expired (means cleared cart). 使用缓存时,只需检索购物车,如果返回null,则表明缓存已过期(意味着已清除购物车)。

Profile is used to persist data across sessions or across logins. 配置文件用于跨会话或登录保留数据。

You should use session to store this user's cart information - http://msdn.microsoft.com/en-us/library/ms178581.aspx . 您应该使用会话存储该用户的购物车信息-http://msdn.microsoft.com/zh-cn/library/ms178581.aspx

Session is a temporary information store that exists for a certain period. 会话是存在一定时间的临时信息存储。 As the sessions automatically expire; 随着会话自动过期; the shopping cart would get cleared after a period. 一段时间后,购物车将被清算。

Sessions can store any piece of information that you need and are in no way limited to login or authentication information. 会话可以存储您需要的任何信息,而绝不仅限于登录或身份验证信息。

Session["ShoppingCart"] = new ShoppingCartExample.Cart();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM