它是一个很好的做法,以避免在ASP.NET MVC中使用会话状态?如果是的话,为什么,怎么样? [英] Is it a good practice to avoid using Session State in ASP.NET MVC? If yes, why and how?

查看:106
本文介绍了它是一个很好的做法,以避免在ASP.NET MVC中使用会话状态?如果是的话,为什么,怎么样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这不是明确写着的地方,但我在ASP.NET MVC阅读一些博客后感觉。刚好奇,想询问在这里的。

It's not explicitly written somewhere but I felt so after reading few blogs on ASP.NET MVC. Just got curious and thought of asking it here.

更新:
我不是问对服务器内存/存储/ RAM的担忧。对他们而言,有来存储会话出过程中的溶液。我知道。我很好奇的是,在那里,我们曾在WebForms的使用Session的任何方案,但我们现在能避免它在MVC采取由MVC提供了很好的结构化的方式受益?

UPDATE:
I'm not asking about memory/storage/RAM concerns on server. For them, there is a solution to store session out of process. I know that. I'm curious that, are there any scenarios where we had to use Session in WebForms but we can avoid it now in MVC taking benefit of the nice structured way offered by MVC?

推荐答案

在ASP.NET Web表单,传递不同的网页之间的信息从来没有使用session特别容易。由于回传为中心的模型,资料可查的服务器作为活动的一部分,但往往在错误的页面显示的结果,使得经过必要的页面之间的信息。

In ASP.NET Web Forms, passing information between different pages was never especially easy without the use of session. Due to the postback-centric model, information was available on the server as part of an event, but often in the wrong page for displaying a result, making passing information between pages necessary.

这往往会导致会话的过度使用,填充旨在表明当前有哪些正在对象与相互作用是会话当前的变量。这种过度反过来提出的申请非常态的依赖性和更难确定预期的行为(这是变量填充?我是否有目前的订单ID吗?)。

This tended to lead to an overuse of session, populating "current" variables in session intended to indicate what the current object being interacted with was. This overuse in turn made applications very state-dependent and much harder to determine expected behaviour ("Is this variable populated?" "Do I have the current order ID yet?").

MVC是围绕你的网站是一个视图到信息的逻辑模型的概念结构。它鼓励有无国籍通过使用简单控制器响应与作为HTTP请求的一部分传递关键信息的操作。操作的

MVC is structured around the idea that your website is a view into a logical model of information. It encourages having stateless operations through the use of simple controllers responding to actions with key information passed as part of the HTTP request.

由于这些特性,会议不再需要在MVC执行基本任务,并成为适应较差的地方以前似乎是一个非常有效的选择。

Because of these properties, session is no longer required to perform basic tasks in MVC, and becomes poor fit where it has seemed a perfectly valid choice before.

从根本上说,会话污染HTTP 。它使得依赖于接收服务器的内部状态请求(通常含有自己的状态)。这就是为什么它视为一个邪恶的东西(虽然经常一个实用和必要的话)。

Fundamentally, session pollutes HTTP. It makes requests (often containing their own state) dependent on the internal state of the receiving server. This is why it's seen as something of an evil (although often a practical and necessary one).

这篇关于它是一个很好的做法,以避免在ASP.NET MVC中使用会话状态?如果是的话,为什么,怎么样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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