简体   繁体   中英

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:

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. 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).

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 .

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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