locked
Shopping cart sessions are not unique for every new user. RRS feed

  • Question

  • User-979789484 posted

    Hello. I've built a shopping cart website for a client www.thebeadshed.com.au

    If i go ahead a put a product into the shopping cart and then close the window.

    Then i goto another computer and repeat the process of adding a product into the shopping cart i see the first product that i added from the first computer. The shopping cart does use a enumable class to hold the entered items and then put into a session.

    I thought that session was uniqure for each new user that comes to the website.

    I have set the application life cycle turned on on the hosting panel but that did not seem to make a difference.

    any suggestions.

    Thank you

    Tuesday, April 2, 2013 9:46 PM

All replies

  • User1082734430 posted

    When you logged in from another computer it start a new session it would not hold the previous values.

    Better approach is get all the products of the user from DB itself.

    Wednesday, April 3, 2013 2:35 AM
  • User381600086 posted

    There seems to be design issue. Check whether you have In proc session or Out proc. I m not sure, you can also check is this session persist in database or caching in cnetralised server.. This could be the probable reason , as it seems you open new window browser and that too in system other than you had logged in. Also check IIS level caching.

     

     

    Wednesday, April 3, 2013 3:29 AM
  • User-1356915459 posted

    How you are storing values into session? I have doubt you are storing kind of list object into session and it is not getting cleared when you login from other machine with same username.

    Tuesday, April 9, 2013 1:33 AM
  • User-1356915459 posted

    How you are storing values into session? I have doubt you are storing kind of list object into session and it is not getting cleared when you login from other machine with same username.

    Tuesday, April 9, 2013 1:33 AM
  • User-979789484 posted

    Hello and thankyou for your reply.

    That is what i have always thought about sessions. lets say i open firefox and add some products into the shopping cart. Then i open internet explorer and add products into the shopping cart. I end up seeing the products that where added to the cart in firefox.......

    so maybe a better approach would be to create a temporary table so when a client adds to cart it wont be using any sessions.

    My host also supports application pooling if its turned off the session does not seem to expire except after 20mins or if i set a higher time in the web.config.

    ive also been trying to find a way to remove the session on window close but i've searched extensivily and still not found a solution about that but that still does not solve the problem with two windows open on 2 seperate computers.

    My shopping cart has 3 files

    1. A serializable class called Shopping cart which is a dictionary which then implements IEnurerable(ShoppingCartItem)

    2. A class called "ShoppingCartItem" that holds the properties of A cart item, eg productid, itemname, quantity etc.. etc..

    If i look at my cart i dont actually put the would shopping cart into a session here is some code for an insert of a cart item

     Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim item As ShoppingCartItem = New ShoppingCartItem()
            Dim ProductID As Integer = Request.QueryString("mytitleid")
            With item
                .ProductWeight = CInt(weighttxt.Text)
                .ID = ProductID
                .Name = Label1.Text
                .Quantity = CInt(quantitytxt.Text)
                .UnitPrice = CDbl(pricetxt.Text)
    
                Dim imagename As String = Image1.ImageUrl
    
                Dim fixedimage As String = imagename.Substring(13)
    
    
    
                .ProductImage = "thumbimages/" & fixedimage
    
    
    
    
            End With
            ShopCartMod.ShopCart.AddItem(item, CInt(quantitytxt.Text))
            Session("ItemsInCart") = "1"
            Response.Redirect("~/Cart.aspx")
        End Sub


    The
      Session("ItemsInCart") = "1"

    is just a check for login purposes.



    I would think that even if im not putting my cart into session that if the window closes the class values would reset.

    Thank you again for feedback has made me think better!!!

    Tuesday, April 9, 2013 5:57 AM
  • User-979789484 posted

    This is how im binding the gridview from the class

     Private Sub BindGridView()
            With gvCart
                gvCart.DataSource = ShopCartMod.ShopCart
                gvCart.DataBind()


                lblCartTotal.Text = String.Format("{0:c}", ShopCartMod.ShopCart.CartTotal)
            End With





            'If Session("Shipping") = "Free Shipping" Then
            '    shippingtxt.Text = 0
            'Else
            '    shippingtxt.Text = Session("Shipping")
            'End If


            'Dim total As Double = CDbl(lblCartTotal.Text) + CDbl(shippingtxt.Text)
            ' totaltxt.Text = String.Format("{0:c}", total)
        End Sub

    Tuesday, April 9, 2013 5:59 AM
  • User-1241139641 posted
    ShopCartMod.ShopCart.AddItem(item, CInt(quantitytxt.Text)) - Is this static?

    Is ShopCartMod.ShopCart a static property?  If yes, your binding the same datasouce (items in the cart) to each new cart you create. So each time you are creating a new cart with 1 more item.

    Wednesday, April 10, 2013 12:00 PM
  • User-979789484 posted

    hello

    this is the shopingcartmod

    Public Module ShopCartMod
        Public ShopCart As New ShoppingCart
    End Module

    This is the

    ShopCartMod.ShopCart.AddItem(item, CInt(quantitytxt.Text)) 

     Public Sub AddItem(ByVal item As ShoppingCartItem, ByVal quantity As Integer)

            If shoppingCartItems.ContainsKey(item.ID) Then
                shoppingCartItems(item.ID).Quantity = quantity
            Else
                shoppingCartItems.Add(item.ID, item)
            End If

            shoppingCartTotal += item.ItemTotal

        End Sub

    Here im check that in the client already has the same product in the cart then keep the quantity the same else add the new item.

    thankz

    Wednesday, April 10, 2013 7:05 PM
  • User-1241139641 posted

    You are creating a Module which means only 1 instance of the class is created.

    If I understand you correctly.. the application acts like 1 cart is shared across all users and everytime you add an item, it shows up in every new cart you create. This is because you are using a 'Module'.

    Try writing the application to this

    Public CLASS ShopCartMod
        Public ShopCart As New ShoppingCart
    End Module



    Wednesday, April 10, 2013 8:18 PM
  • User-979789484 posted

    thank you psinet

    as i have now relized about module sharing variable accross for all user.. omg what a mistake i have made. I have tried changing the module to a class though it breaks the whole application.

    Is there any way that i could make the module unique for each user. Im guesss that there is not but worth the ask any ways.  thank you.

    Tuesday, April 16, 2013 9:59 PM
  • User-1241139641 posted

    No, a module can't be made unqiue to a user. The whole point of this type of object is to only have a single instance at a time. I think any sort of change that you might try to keep the module will mean having to change portions of your mode no matter what.

    Wednesday, April 17, 2013 9:39 AM