Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 597111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:14:41+00:00 2026-05-13T16:14:41+00:00

I have created a simple shopping cart application. We needed something specific to our

  • 0

I have created a simple shopping cart application. We needed something specific to our needs, long story. Anyway, I am storing the cart object in a cookie. That work fine, but I am having trouble with deleting the cart cookie from within the class. The cart object contains a collection of products (iList). Here is the code I use to delete the cookie:
My Empty Cart Code:

Dim currentCookie As HttpCookie = HttpContext.Current.Response.Cookies(cookieName)
currentCookie.Expires = DateTime.Now.AddYears(-30)
HttpContext.Current.Response.Cookies.Add(currentCookie)

My LoadCartFromCookie code:

if not HttpContext.Current.Request.Cookies(theCookieName) is nothing then
     _cart =  CType(HttpContext.Current.Request.Cookies(theCookieName).value,Cart)
End If

My cart class constructor first tries to load the cart from the cookie. If it finds the cookie then it loads the cart object otherwise it creates a new instance of the cart without any details. For some reason even if I run the delete cookie (Empty cart) code and then run my LoadCartFromCookie code (From inside the Cart class) it still loades the expired cookie. Any thoughts? I thought it might have been a browser issue, but I tried IE8, FF 3.5, and Chrome. If inside the codebehind for and ASPX page I try looking for the expired cookie (Request.Cookies(theName)) , it never finds it. Which is what I want it to do inside the class.

Daniel

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T16:14:41+00:00Added an answer on May 13, 2026 at 4:14 pm

    are you running the statements back to back or on the next postback?

    You are just loading an expired cookie because you didn’t remove a cookie, you just added an expired cookie, no?

    Enter what seems like a catch 22 but is actually a code smell….

    To delete a cookie on the browser you have to send an expired cookie. But if you are using a cookie as a data object in your code on the same cycle you then have to manage the cookie collection.

    Either dedicate one postback to just deleting the cookie or use a clr object to keep track of your cart while in the codebehind. e.g. load the cookie into an object on page_load and set the cookie from the object before you exit but do not reference the Cookies collection.

    p.s. While I haven’t wrasseled with cookies for a while, if you want to REPLACE a cookie, try Cookies.Remove() and add the new one, it should replace the old one on the browser while keeping a single valid cookie in the collection for you. But I still don’t recommend using the cookie collection as data storage in your code behind classes…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created my own simple shopping cart following the Music store mvc example. Problem
I have a requirement to develop a shopping cart Android application. The features should
Could someone help me on this, I have created simple web services using axis2
How to manually create Friendly URLs? (PHP) So I have created simple php file
I am new to Repository concept and get some questions. I have created simple
I have created the simple web service. Code: [ServiceContract] public interface ITsdxService { [OperationContract]
I have created this simple program to learn shared_ptr using namespace std; #define Yes
I have created very simple app with persistence context (hibernate as provider) to read
I have created a simple test form with FormBorderStyle = FixedToolWindow by default and
i have created a simple public ref class in the vc++ project, which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.