ASP.NET MVC使用会话 [英] ASP.NET MVC Session usage

查看:107
本文介绍了ASP.NET MVC使用会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我使用的ViewData或TempData的在我的ASP.NET MVC应用程序对象持久化。

Currently I am using ViewData or TempData for object persistance in my ASP.NET MVC application.

不过在我的对象存储到ViewData的通过我的基础类少数情况下,我打了数据库中每个请求(当计算机[无所谓] == NULL)。

However in a few cases where I am storing objects into ViewData through my base controller class, I am hitting the database on every request (when ViewData["whatever"] == null).

这将是很好用更长的寿命,即会话保存这些弄成。同样,在一个订单处理管道,我不希望之类的东西才能被保存在数据库创建。我宁愿填充对象在内存中,然后当为了达到一定的状态,保存它。

It would be good to persist these into something with a longer lifespan, namely session. Similarly in an order processing pipeline, I don't want things like Order to be saved to the database on creation. I would rather populate the object in memory and then when the order gets to a certain state, save it.

所以,它似乎是会话是这样做的最好的地方?或者你会建议,在秩序的情况下,从数据库中检索的顺序在每个请求,而不是使用会话?

So it would seem that session is the best place for this? Or would you recommend that in the case of order, to retrieve the order from the database on each request, rather than using session?

想法,建议AP preciated。
谢谢

Thoughts, suggestions appreciated. Thanks Ben

推荐答案

我相信这是会议的目的是为 - 临时存储会话的具体数据。

I believe this is what Session was designed for - to temporarily store session specific data.

不过,由于增加使用会话,即使微不足道的连接复杂性 - 在我自己的ASP.NET MVC项目,我决定打数据库中的每个订单创建步骤页面上(仅ID在步骤之间传递) 。我准备优化和立即开始使用会话,我会看到额外的数据库击中为每个请求的性能瓶颈。

However, due to increased complexity connected with using the Session, even if negligible - in my own ASP.NET MVC project, I have decided to hit the database on every Order creation step page (only ID is passed between the steps). I am ready to optimize and start using session as soon as I will see that the extra database hit for every request is a performance bottleneck.

这篇关于ASP.NET MVC使用会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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