ASP.NET 大师:使用会话变量的优点/缺点是什么? [英] ASP.NET Masters: What are the advantages / disadvantages of using Session variables?

查看:17
本文介绍了ASP.NET 大师:使用会话变量的优点/缺点是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经对这个主题进行了搜索,并且一遍又一遍地找到了相同的数据——对三种不同类型的会话的回顾.(InProc、Sql、StateServer)但是,我的问题性质不同.

I've done a search on this subject already, and have found the same data over and over-- a review of the three different types of sessions. (InProc, Sql, StateServer) However, my question is of a different nature.

具体来说,首先使用内置 .NET 会话有什么优点/缺点?

Specifically, what is the advantages/disadvantages of using the built in .NET session in the first place?

这就是我问的原因:一位 .NET 开发人员告诉我永远不要使用内置的 Microsoft Session.一点也不.甚至不创建自定义会话状态提供程序.他的理由如下——如果您在 IIS 中打开了 Session,它会使您的所有请求同步发生.他说启用会话会降低 Web 服务器的性能.

Here is why I am asking: A fellow .NET developer has told me to NEVER use the built in Microsoft Session. Not at all. Not even create a custom Session State Provider. His reasoning for this is the following--that if you have the Session turned on in IIS it makes all of your requests happen synchronously. He says that enabling session degrades the performance of a web server.

他对此的解决方案是自己创建一个会话——一个存储您需要的所有值的类,并在数据库中进行序列化.他建议您存储唯一 ID 以在 cookie 或查询字符串变量中引用它.在我们的环境中,需要使用 DB 来存储会话,因为我们制作的所有页面都在 Web 场中,而且我们使用 Oracle——所以我同意这一部分.

His solution to this is to create a session yourself-- a class that stores all values you need and is serialized in and out of the database. He advises that you store the unique ID to reference this in a cookie or a querystring variable. In our environment, using a DB to store the sessions is a requirement because all the pages we make are on web farms, and we use Oracle-- so I agree with that part.

使用内置 Session 是否比使用自制 Session 更能降低性能?这有任何安全问题吗?

Does using the built in Session degrade performance more than a home-built Session? Are there any security concerns with this?

总结一下,有什么优点/缺点?

So to sum it all up, what are the advantages/disadvantages?

感谢所有回答的人!

推荐答案

首先,浏览器只会在给定的时间向给定的主机名发出两个请求.大多数情况下,这些请求是针对静态内容(JS 文件、CSS 等)的.因此,对动态内容的请求的序列化几乎不是人们可能想到的问题.另外,我认为这可能与 Classic ASP 混淆,其中使用 Session 的页面肯定是序列化的,我不相信 ASP.Net 是这种情况.

First, a browser will only make two requests, to a given hostname, at a given time. For the most part these requests are for static content (JS files, CSS, etc). So, the serializing of requests to dynamic content aren't nearly the issue that one might think. Also, I think this may be confused with Classic ASP, where pages that use Session are definitely serialized, I don't believe this is the case with ASP.Net.

使用 ASP.Net 会话状态(SQL 模式、状态服务器或自定义),您可以在整个应用程序中实现标准且一致的实现.如果您不需要共享会话信息,这是您最好的选择.如果您需要与其他应用程序环境(php、swing/java、经典 asp 等)共享信息,可能值得考虑.

With ASP.Net session state (SQL mode, state server, or custom) you have an implementation that is standard, and consistent throughout an application. If you don't need to share session information this is your best bet. If you need to share information with other application environments (php, swing/java, classic asp, etc.) it may be worth considering.

另一个优点/缺点是,即使与不同的提供商合作,很多开发人员都专注于会话的内置方法,以提高性能和设计,而不是滚动您自己的方法.

Another advantage/disadvantage is that there has been a lot of developer focus on the built-in methodology for sessions with regards to performance, and design over rolling your own, even with a different provider.

这篇关于ASP.NET 大师:使用会话变量的优点/缺点是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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