我每次都得到新的GUID! [英] I get new GUID every time!

查看:78
本文介绍了我每次都得到新的GUID!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在使用ASP.NET和VB.Net构建一个小型在线商店。

我有3页:< u>主页,产品详情购物车

主页显示所有产品网格视图。当用户点击产品时,他/她将被重定向到产品详细信息页面。在此页面中,如果用户单击购买按钮,则会发生以下两件事: 1。 insert语句将产品ID和GUID带到数据库 2。用户被重定向到购物车页面以查看他/她的物品。



问题是当我去检查当前会话的篮子表时,每行的GUID是不同的。我想在篮子桌上看到这样的东西:



ProductID ....... GUID

1 ................... 6719c79a-2952-4615-8441-ecc06d7ecc77

2 ... ................ 6719c79a-2952-4615-8441-ecc06d7ecc77

3 ................ ... ... 6719c79a-2952-4615-8441-ecc06d7ecc77





后面的代码可能会解释更多,这是我写的产品详细信息页面



页面加载事件:

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





我的问题是:我怎样才能保留相同的GUID用户,直到他/她结账或离开网站?



请帮我整理这个问题。

最后,抱歉弱语。



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.

推荐答案

我仍然不太清楚这些碎片是如何组合在一起的,但试试这个:

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



这样,GUID只会在会话中放置,如果它还不存在。


That way, the GUID will only be placed in session if it doesn''t already exist.


因为一切都在一个站点而且没有独立的参与创建ID,你根本不需要GUID。它可能只是像UInt32或UInt64 ID。您的服务器是发布ID的中心点,因此您可以保证完美的唯一性。使用GUID是完全没有意义的。



-SA
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


这篇关于我每次都得到新的GUID!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆