对于 ASP.NET 中的会话状态模式,InProc 和 SQL Server 哪一个更好?
我正在开发一个 ASP.NET 网站。我想知道会话状态模式下哪个更好:InProc 或 SQL Server?我需要听听您在这个问题上的经历。
另一个问题是关于 cookieless 属性。如果我将其设置为 true,我的网站是否存在安全漏洞?在我在 MSDN 站点上看到的所有示例中,此属性都设置为 false。
最后一个问题是关于 Timeout 属性的。当我将其设置为 InProc 模式时,此属性是否会影响我的会话生命周期?
I am developing an ASP.NET website. I want to know which one is better in session state mode: InProc or SQL Server? I need to hear about your experiences on this issue.
Another question is about cookieless attribute. Is there any security hole in my site if I set it to true? In all the samples I saw in MSDN site, this attribute was set to false.
And the last question is about Timeout attribute. Does this attribute effect my sessions lifetime when I set it to InProc mode?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从什么方面来说比较好?
InProc 会话速度要快得多,要求较少(序列化),但当您在多个 Web 服务器上运行应用程序时不可用;
Sql 会话 速度慢得多,具有对象序列化要求,但可以在多个 Web 服务器之间共享;
这是开发人员应该最关心的它们之间的主要区别。
无 Cookie 会话
如果您关闭 cookie 会话 ID 处理,您将能够看到会话 ID。但如果你检查cookies,你也可以。号码就在那里。
会话 cookie 过期时间设置为浏览器会话,因此在持久性方面实际上是相同的。
如果您知道对方的会话 ID,则会话可能会被劫持。当然,如果您使用无 cookie 会话,那就更容易了,因为您所要做的就是更改 URL...
并且复制 URL 和共享/保存(收藏夹)还有另一件事。我想我不必解释这个问题。
默认情况下,无 Cookie 会话为
false
,因为绝大多数浏览器都支持 Cookie。 只有当您知道您的客户端不会有 cookie 时才应将其打开。会话超时
会话超时始终与会话过期相关,无论会话类型如何。但您必须注意,当您使用 SQL Express 版本时,SQL 会话状态可能不遵守此设置,因为您需要 SQL Server 代理服务来丢弃过期的会话。您可以通过编写自己的 Windows 服务来丢弃过期会话来缓解此问题。
Better in terms of what?
InProc session is much much faster, has less requirements (serialization), but unusable when you're running your application on several web servers;
Sql session is much slower, has object serialization requirements, but can be shared between several web servers;
That's the main difference between them that developers should mostly care about.
Cookieless session
If you turn off cookie session ID handling you will be able to see Session ID. But so can you if you check cookies. The number is there.
And Session cookie expiration is set to browser session so it's practically the same in terms of persistence.
Sessions can be hijacked if you know other party's Session ID. It's easier of course if you use cookieless sessions because all you have to do is to change URL...
And there's another thing with copying URLs and sharing/saving (Favourites). I suppose I don't have to explain the problem.
Cookieless sessions are
false
by default because vast majority of browsers support cookies. You should only turn it on when you know your clients won't have cookies.Session Timeout
Session timeout is always related to session expiration regardless of session type. But you have to be aware that SQL session state may not obey this setting when you use SQL Express editions because you need SQL Server Agent service to discard expired sessions. You can mitigate this problem by writing you own Windows Service that discards expired sessions.
您可以通过 3 种方式使用 Session。每种方法都有优点和缺点
In-Proc:
一台服务器。这对您不起作用
会话状态:
Sql Server:
也查看这个问题:
SQLServer 与 StateServer 的 ASP.NET 会话状态性能
You can use Session in 3 ways. Each one has advantages and disadvantages
In-Proc :
one server. This wont work for you
Session State :
Sql Server:
Check out this question also :
SQLServer vs StateServer for ASP.NET Session State Performance
InProc Session State
InProc会话模式表示会话状态存储在本地,意味着采用InProc会话状态模式是
将对象存储在 Web 应用程序的 AppDomain 中。因此,当 IIS(Internet 信息系统)重新启动时,会话状态会丢失。
一般情况下,AppDomain的重启是基于memoryLimit属性等几个因素
我们可以使用StateServer或SqlServer
会话状态模式来克服这些问题,这里会话状态不存储在Web应用程序的AppDomain中。
OutProc Session State
在 OutProc Session 中,Sessin State 存储在 StateServer 和 SqlServer 模式中,而不是存储在 Web 应用程序的 AppDomain 中。
StateServer:它使用独立的Microsoft Windows服务来存储会话变量,因此该服务
独立于IIS,可以运行在单独的服务器上。
您可以将此模式用于负载平衡解决方案,因为多个 Web 服务器可以共享会话变量。
虽然重新启动 IIS 时会话变量不会丢失,但跨进程边界时性能会受到影响。
SqlServer: SqlServer 模式还使您能够利用位于 IIS 进程之外的状态存储,并且可以
位于本地计算机或远程服务器上。对于会话信息的持久化,可以使用SqlServer模式
SqlServer 模式与进程外模式类似,只不过会话数据保存在 SQL Server 中。
InProc Session State
InProc session mode indicates that session state is stored locally, means that with InProc session state mode is
store objects in the AppDomain of the Web application.Because of this the session state is lost when IIS (Internet Information System) restarts.
Generally, the AppDomain is restarted based on several factors like memoryLimit attribute
settings in the section of the configuration file, modifiying Global.asax or the Web.config file etc.
We can use StateServer or SqlServer session state mode for overcome these issues and here session state is not stored in the AppDomain of the Web application.
OutProc Session State
In OutProc Session ,Sessin State is stored In the StateServer and SqlServer modes not in the AppDomain of the Web application.
StateServer: it uses a stand-alone Microsoft Windows service to store session variable, so this service
is independent of IIS, it can run on a separate server.
You can use this mode for a load-balancing solution because multiple Web servers can share session variables.
Although session variables are not lost if you restart IIS, performance is impacted when you cross process boundaries.
SqlServer: SqlServer mode also enables you to utilize a state store that is located out of the IIS process and that can be
located on the local computer or a remote server. For persistence of session information, you can use SqlServer mode
SqlServer mode is similar to out-of-process mode, except that the session data is maintained in a SQL Server.