Aierong [Original]
The first time to do BTOC site shopping cart, summed up the shopping cart in the way the data stored
Mode 1: Using the session
A session can hold any type of data, each user has a unique session ID, using this ID to differentiate between different users ' shopping carts
Session data is stored in the Web server's memory, and if more users are using the shopping cart, this will consume a large amount of server resources
Session has a small flaw, it relies on cookies to communicate with the user, once the user turned off the cookie, the use of the session will be more trouble
Of course, in ASP. NET, there are 2 other ways to save session data
One is to specify another server to hold session data, which can effectively share the cost of running the Web server.
The other is to store session data in MS SQL, MS SQL is implemented with local temporary tables, session data is placed in local temporary tables, and MS SQL assigns a unique ID to each local temporary table.
, I would like to use this ID to distinguish between different user's session data. But I do not recommend using this method, frequently in the database to create and delete temporary tables on the database is too much overhead
Mode 2: Inside the database with the table (Shopingcart)
The way I like to realize
Table has several basic fields
Cartid Shopping Cart ID (unique)
ID of the item (unique)
Number of items purchased by Qty users
CreateDate Shopping Cart creation time
The field cartid of this table is the ID of the shopping cart that distinguishes the different users, and if the user is logged in, you can place the ID of the login of the user in the table, if the user does not use the shopping cart,
You can assign him a GUID (the world's only sign) to do the shopping cart ID
This method has some drawbacks, one is that it will result in a large number of invalid data, we all know that the use of shopping carts, people will not necessarily end up buying goods. But using a shopping cart will have to
Insert the relevant data into the table (Shopingcart), without landing the user left the site, his data in the table became a heap of waste data, because the next time he landed, we assigned to his
is a new Cartid shopping cart ID. There are waste data we have to maintain this table, we can write a process to clean up the waste data (using the field createdate and Cartid can judge invalid data), human call run can also, if you want to run by MS SQL Generation, You can set up a job that the job automatically calls processes to clear waste data
Say pull defect we should talk about the advantages of this way pull
1. Less system resources, we can put the database in a computer, the Web server installed in another computer, the system resources to fully play
2. The data in the shopping cart can be effectively retained, we can imagine a customer when shopping, suddenly some other reason (crash and other reasons) left the shopping station, he in the shopping cart data effectively protect
Stay, the next time he landed the shopping cart also has the last data retained, to prevent users to purchase goods again operation (this feature only to the user's shopping cart valid), if the session to achieve
Shopping cart, all users once left the site, the data in his shopping cart all failed
OK, so I summed up these, as I just contacted the ASP. NET, for many aspects also do not know much, there may be some other ways to achieve shopping cart, I hope we can give guidance, thank you