开发者

Where to store Shopping Cart in MVC Application?

I am working on a Railway Portal and would require maintaining a shopping cart of components user has selected, there could be multiple components of different type in the cart. I don't see a value in storing the cart in database, would like to store the final order in DB. Where can I store/hold (temporary) the cart data per user session in MVC? All MVC samples I saw online save the cart data in DB – not sure why.

MVC presentation layer will be communicating with external web services for pricing and availability of these components, so I can't store only the product IDs to do a lookup for actual product descriptions/prices during the shopping process... I have to store everything in the cart (Product IDs, Descriptions, Prices etc) some place in memory. My application will be running in WEB FARM environme开发者_运维问答nt and cannot use in-process session storage. Options come to my mind are:

  1. SESSION STATE in SQL SERVER
  2. Using some kind of Distributed Caching Mechanism to store Session data such as “Windows Server AppFabric”


It's always an option to store this data in an encrypted client cookie. Ruby on rails does this and it scales very well.

See http://agilewebdevelopment.com/plugins/encrypted_cookie_store for more details on how Ruby does this. Don't know how you would implement this with ASP.Net MVC.


The cart is stored in the database so that it may be persisted across sessions if desired.

Additionally, by storing it in the database, you gain additional info that you can query against, such as Which items do my customers want that they have not purchased yet?

Even if you don't want that feature now, put it in the db, as addding that functionality later will be much more difficult, while it is fairly easy to do upfront.


Shopping carts are perfect matches for document databases. I would recommend looking at RavenDB, Redis, MongoDB, CouchDB for starters.

If you want extreme performance your notion to use App Fabric is already there, after that you can persist the cart to any durable store since performance is a relatively moot point then.


Although it is tempting to store the cart in a hidden field as an encrypted string, this would be wrong, as most users would expect their cart to retain its state.

Imagine if amazon's shopping cart didn't persist over sessions. They would not sell nearly as many books, electronics or whatever.

When in doubt, take a look at an equivalent site that is successful and see what they have done. This applies to all things in life, not just websites.


Store cart detail in database and cart reference in cookie for identifying for particular browser/client.

e.g

tblCart (refId,proId,qty)

refId and ProId will be Primary key.

refId store in cookie

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜