MVC2购物车最佳做法 [英] MVC2 shopping cart best practices

查看:78
本文介绍了MVC2购物车最佳做法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在使用mvc2开发购物车.我只想知道什么是暂时保存购物车数据的最佳实践.

db或会话

如果是会话,可以有人提供一些示例(c#)..

问候

Hi,
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

推荐答案

使用SqlServer会话状态存储将购物车存储在会话中.

这样,您可以获得数据库存储的可靠性以及会话的短生命期.

我敢肯定,如果您稍稍钻探网络,就会发现如何在会话中存储内容.
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.


另一种方法是使用ViewData传输,而不是通过视图,并且仅在完成购物车流程时将其保存到数据存储区(例如SqlServer).

通过MVC 2框架的基本定义,该视图应该是无状态的.除此以外,会话数据和缓存也被视为安全漏洞,可以在客户端浏览器中禁用.

缺点是,如果用户在购物工作流程的中间走出您的网站(或转到未维护视图数据的页面),购物车信息就会丢失.
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.


这篇关于MVC2购物车最佳做法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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