Click here to Skip to main content
15,878,602 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am developing shopping cart by using mvc2.I just want to know what is the best practice to save shopping cart data temporally.

Db or session

if it is session can some one provide few samples(c#)..

kind regards

Store the cart in session using a SqlServer Session State Store.

This way, you get the reliability of the database store plus the short lifetime of session.

I'm sure if you dig around the net a bit you'll find out how to store things in session.
Share this answer
Another approach would be use the ViewData transfer not persisted data through the views and only save it to the datastore (the SqlServer for instance) when you finish the shopping cart process.

By the essencial definition of the MVC 2 framework the view should be stateless. In addition to that session data and cache is considered a security breach and may be disabled in the client browser.

The drawback is that the cart information is lost if the user step out of your site (or go for a page where the viewdata is not maintained) in the middle of the shopping workflow.
Share this answer

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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900