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

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

问题描述

为什么这样说我们不应该使用在ASP.NET MVC应用程序会话变量?我碰到来到这个答案这是这么说的。在这种情况下,我将如何保持整个请求的数值一样登录用户信息,并关联到他的帐户一些相关的数据?

这是的达林答案。


  

为什么要使用HttpContext.Current在ASP.NET MVC应用程序?
  不要使用它。这是邪恶的,即使在经典ASP.NET web表单
  而且还可以用于ASP.NET MVC这是一个灾难的发生所有的乐趣
  出这个漂亮的Web框架。



解决方案

一个像ASP.NET MVC框架的基本原则是,他们的无国籍的,就像网络是。 ASP.NET Web窗体是模仿范式状态在一个无状态的环境的一种尝试。 这是一个谎言,换句话说。

在ASP.NET MVC应用程序中使用Session变量有点像绑喇叭一匹马的头,称这是一个独角兽。

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?

This is Darin's answer.

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.

解决方案

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.

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天全站免登陆