Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET session VB.NET
Hi all,
I'm in the middle of building a small online shop using ASP.NET and VB.Net.
I have 3 pages: Home, Product Details and Shopping Cart.
The Home Page displays all products in a Grid View. When a user clicks on a product, he/she gets redirected to the Product Details page. In this page, if the user clicks on the Buy button, two things happen here: 1. an insert statement takes the Product ID and the GUID to the database 2. the user gets redirected to the Shopping Cart page to view his/her items.
 
The problem is that when I go check the Basket table for the current session, the GUID is different in each row. I suppose to see something like this in the Basket table:
 
ProductID.......GUID
1 ................... 6719c79a-2952-4615-8441-ecc06d7ecc77
2 ................... 6719c79a-2952-4615-8441-ecc06d7ecc77
3 ................... 6719c79a-2952-4615-8441-ecc06d7ecc77
 

The code behind might explain more, here is what I have written in the Product Details page:
 
Page Load Event:
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
      If Not IsPostBack Then
          Session("guid") = Guid.NewGuid().ToString()
      End If
End Sub
 
Button Click Event
Protected Sub Button3_Click(sender As Object, e As System.EventArgs)
        Dim insert As New DataSet1TableAdapters.BasketTableAdapter
        insert.InsertQuery(Me.Request.QueryString("ProductID"), Me.Session("guid"))
        Response.Redirect("MyShoppingCart.aspx")
End Sub
 
My question is: how can I retain the same GUID for a user until he/she checkout or leave the website?
 
Please help me sorting this issue.
Finally, sorry for the weak language.
Posted 27-Mar-13 14:54pm
Comments
AspDotNetDev at 27-Mar-13 20:57pm
   
FYI, I deleted the answer you posted, as it should have been posted as a comment. Also, glad I could be of assistance :-)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I'm still not too clear on how the pieces fit together, but try this:
If Session("guid") Is Nothing Then
    Session("guid") = Guid.NewGuid().ToString()
End If
That way, the GUID will only be placed in session if it doesn't already exist.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

As everything is in just one site and there are no independent partied creating IDs, you don't need GUID at all. It could be just something like UInt32 or UInt64 ID. Your server is a central point issuing the IDs, so you can guarantee perfect uniqueness. Using GUID is totally pointless.
 
—SA
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 480
1 Maciej Los 330
2 Richard MacCutchan 225
3 BillWoodruff 185
4 Suraj Sahoo | Coding Passion 155
0 OriginalGriff 8,759
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,269
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web03 | 2.8.1411028.1 | Last Updated 27 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100