簡體   English   中英

在一定時間后如何在asp.net中自動清除購物車

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

我創建了一個電子商務網站。 我的問題是,如果用戶在登錄或未登錄后將商品添加到購物車中之后離開站點,我想在一個確定的時期后自行清除購物車。

我的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,則表明緩存已過期(意味着已清除購物車)。

配置文件用於跨會話或登錄保留數據。

您應該使用會話存儲該用戶的購物車信息-http://msdn.microsoft.com/zh-cn/library/ms178581.aspx

會話是存在一定時間的臨時信息存儲。 隨着會話自動過期; 一段時間后,購物車將被清算。

會話可以存儲您需要的任何信息,而絕不僅限於登錄或身份驗證信息。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM