为什么会话是 ASP.NET MVC 应用程序中的灾难? [英] Why Session is a disaster in ASP.NET MVC application?

查看:26
本文介绍了为什么会话是 ASP.NET MVC 应用程序中的灾难?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么说我们不应该在 ASP.NET MVC 应用程序中使用会话变量?我遇到了这个答案,它是这么说的.在这种情况下,我将如何跨请求维护值,例如登录用户信息和与他的帐户相关的一些相关数据?

Why is it being said We should not use Session variables in ASP.NET MVC applications ? I came across this answer which says so. In that case how will i maintain the values across requests like Logged in User information and some relevant data associated to his account?

这是达林的回答.

为什么在 ASP.NET MVC 应用程序中使用 HttpContext.Current?永远不要使用它.即使在经典的 ASP.NET webforms 中,这也是邪恶的应用程序,但在 ASP.NET MVC 中,这是一场灾难,带走了所有的乐趣出自这个漂亮的网络框架.

Why are you using HttpContext.Current in an ASP.NET MVC application? Never use it. That's evil even in classic ASP.NET webforms applications but in ASP.NET MVC it's a disaster that takes all the fun out of this nice web framework.

推荐答案

像 ASP.NET MVC 这样的框架的基本原则之一是它们是无状态,就像 Web 一样.ASP.NET Web 窗体试图在无状态环境中模仿有状态范式.换句话说,这是谎言.

One of the fundamental principles of frameworks like ASP.NET MVC is that they are stateless, just like the Web is. ASP.NET Web Forms is an attempt to mimic a stateful paradigm over a stateless enviroment. It is a lie, in other words.

在 ASP.NET MVC 应用程序中使用 Session 变量有点像将角系在马头上,并称其为独角兽.

Using Session variable in an ASP.NET MVC application is a bit like tying a horn to a horse's head, and calling it a Unicorn.

这篇关于为什么会话是 ASP.NET MVC 应用程序中的灾难?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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