Asp.Net MVC和会话 [英] Asp.Net MVC and Session

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

问题描述

我想构建在不同的步骤对象在一个asp.net MVC应用程序,每个步骤是不同的页面。诸如此类的事情,你会在会话存储在一个快速Web.Forms应用程序。

I'd like to construct an object in different steps in an asp.net mvc application, each step being a different page. The sort of thing you'd store in Session in a quick Web.Forms application.

阅读它,会议似乎并没有把我当成一件很asp.net MVC'ish。不过,我真的不能相信其他办法,以这种情况作为的TempData和ViewData的似乎不适合任,所以也许我错了。

Reading about it, Session doesn't seem to me as something very asp.net MVC'ish. However I can't really think of other alternatives to this situation as TempData and ViewData don't seem to fit either, so maybe I'm wrong.

当然,我可以把在一个页面,显示/隐藏的4个步骤,但是这不是我点的问题。我想听听您对会议的意见MVC中,如果它是对这种多步骤的问题一个很好的形式给出,或你会做它在其他方面。

Of course I could put the 4 steps in one page and show/hide, but that's not my point with the question. I'd like to hear your opinion about Session in MVC, if it's a good aproach for this kind of multi-step problem or you tend to do it in other ways.

这是非常像ASP.NET MVC 问题会话变量,但我不是在寻找如何访问会话,但如果是为了解决该问题的最好办法或者有更好的东西我缺少Asp.Net MVC。

This is very much like question Session variables in ASP.NET MVC, except that I'm not looking for how to access Session, but if it's the best way to solve such a problem or there is something better I'm missing in Asp.Net MVC.

在此先感谢

推荐答案

有什么未MVC有关会议,其网络的重要组成部分,大多数网站以某种方式使用它。你真的有两个主要选择。无论是存储对象页之间的数据库(这意味​​着节约了一个不完整的对象),或者把它放在会话。两者都有优点和缺点。

There is nothing un-MVC about Session, its a vital part of the web and most sites use it in some way. You really have two main options. Either store the object in the database between pages (which means saving an incomplete object) or put it in session. Both have advantages and disadvantages.

在会议上,你不必部分对象保存到数据库中,但如果用户离开或会话超时,你失去所有这些信息。它也可以导致每个用户更大的内存占用,当你得到它结垢导致一些其他问题。 (所有这一切都可以在负载平衡器或中央会话存储使用粘性会话来解决)。

In session you don't have to save a partial object to the database, but if the user leaves or the session times out you lose all that information. It can also lead to a larger memory footprint per user and when you get to scaling it causes some other problems. (all of which can be solved using sticky-session on a load balancer or central session store).

该数据库的方式是在很多方面更好,但通常你不想不完整的对象保存到数据库中,一是妥协是创建另一个表并保存序列化到该表的对象。它不是要通过你的真实的表,所以你不必在你的数据库约束妥协。 (你也可以在数据库中存储会话数据它基本上做同样的事情)

The database way is better in lots of ways but usually you don't want to save incomplete object to the database, one compromise is to create another table and to save the object serialized to that table. Its not going through your real tables and so you don't have to compromise on your database constraints. (you can also store session data in the database which is basically doing the same thing)

在结束它的两种方式之间的主观判断,我都用了多年了。

In the end its a judgment call between the two ways, I have used both over the years.

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

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