This is in regards to a situation where Session is used to store some temporary data - one example being information entered during a multi-step registration process.
这是关于Session用于存储一些临时数据的情况 - 一个例子是在多步骤注册过程中输入的信息。
If a website has a number of such sections - which wants to utilize the session as temporary data store for pages within the section, what is a good way of cleaning up the session when the data is no longer required, considering that the user may simply navigate away from the section so the pages themselves cannot be used for cleaning up.
如果一个网站有许多这样的部分 - 希望利用该会话作为该部分内页面的临时数据存储,那么在不再需要数据时清理会话的好方法是什么,考虑到用户可能只是导航远离该部分,因此页面本身不能用于清理。
[Edit] In my case, the prime drive for this is to reduce network traffic as session is stored out of proc, but same concern can apply for memory bound applications and performance in general. Also unexpected data in Session can easily lead to difficult to track bugs.
[编辑]在我的情况下,主要的驱动器是减少网络流量,因为会话存储在proc之外,但同样的问题可以适用于内存绑定应用程序和性能。 Session中的意外数据也很容易导致难以跟踪的错误。
4 个解决方案
#1
2
Time should keep the session clean. Sessions should expire and in doing so nuke all their data. This is default behaviour.
时间应该保持会议清洁。会话应该过期,并且这样做会对所有数据进行核对。这是默认行为。
I'll agree that storing too much data in a session is not a great thing for server-resources but as you know, it's sometimes a necessary evil. If you're really that bothered, consider moving your sessions off to SQL Server. It'll add a smidge of latency but you'll be able to handle far more users.
我同意在会话中存储太多数据对服务器资源来说并不是一件好事,但正如你所知,它有时是一个必要的恶。如果您真的感到困扰,请考虑将会话移至SQL Server。它会增加一些延迟,但你将能够处理更多的用户。
#2
0
If you want to store bulk data you have following alternatives:
如果要存储批量数据,您可以使用以下备选方案:
- Cache
- Database
It is not recommended to store large amount of data in the session.
建议不要在会话中存储大量数据。
#3
0
Why not store everything in the database? That's just cleaner.
为什么不将所有内容存储在数据库中那个更干净。
Why? Well, most modern web apps hit the database over a dozen times for each pageview, so a few extra simple queries shouldn't impact performance significantly.
为什么?好吧,大多数现代网络应用程序针对每个网页浏览数十次访问数据库,因此一些额外的简单查询不会显着影响性能。
Having said that, there's nothing wrong with storing a lot of user-generated data in a session, especially if you're using file-based sessions.
话虽如此,在会话中存储大量用户生成的数据并没有错,特别是如果您使用的是基于文件的会话。
Why? How much text can a single person possibly type into a registration form, really? Anything under 4000 bytes will take the same amount of space: one OS page!
为什么?真的,一个人可以在注册表中输入多少文字? 4000字节以下的任何内容都将占用相同的空间:一个操作系统页面!
#4
0
You can design a multi-step registration process without using session storage or using the database to store the temporary data. You can design one .aspx page with multiple panels that you make visible one panel at a time. When the user finishes the last panel, you will still have access to all the previously filled-out controls.
您可以设计多步骤注册过程,而无需使用会话存储或使用数据库存储临时数据。您可以设计一个.aspx页面,其中包含多个面板,您可以一次看到一个面板。当用户完成最后一个面板时,您仍然可以访问所有以前填写的控件。
#1
2
Time should keep the session clean. Sessions should expire and in doing so nuke all their data. This is default behaviour.
时间应该保持会议清洁。会话应该过期,并且这样做会对所有数据进行核对。这是默认行为。
I'll agree that storing too much data in a session is not a great thing for server-resources but as you know, it's sometimes a necessary evil. If you're really that bothered, consider moving your sessions off to SQL Server. It'll add a smidge of latency but you'll be able to handle far more users.
我同意在会话中存储太多数据对服务器资源来说并不是一件好事,但正如你所知,它有时是一个必要的恶。如果您真的感到困扰,请考虑将会话移至SQL Server。它会增加一些延迟,但你将能够处理更多的用户。
#2
0
If you want to store bulk data you have following alternatives:
如果要存储批量数据,您可以使用以下备选方案:
- Cache
- Database
It is not recommended to store large amount of data in the session.
建议不要在会话中存储大量数据。
#3
0
Why not store everything in the database? That's just cleaner.
为什么不将所有内容存储在数据库中那个更干净。
Why? Well, most modern web apps hit the database over a dozen times for each pageview, so a few extra simple queries shouldn't impact performance significantly.
为什么?好吧,大多数现代网络应用程序针对每个网页浏览数十次访问数据库,因此一些额外的简单查询不会显着影响性能。
Having said that, there's nothing wrong with storing a lot of user-generated data in a session, especially if you're using file-based sessions.
话虽如此,在会话中存储大量用户生成的数据并没有错,特别是如果您使用的是基于文件的会话。
Why? How much text can a single person possibly type into a registration form, really? Anything under 4000 bytes will take the same amount of space: one OS page!
为什么?真的,一个人可以在注册表中输入多少文字? 4000字节以下的任何内容都将占用相同的空间:一个操作系统页面!
#4
0
You can design a multi-step registration process without using session storage or using the database to store the temporary data. You can design one .aspx page with multiple panels that you make visible one panel at a time. When the user finishes the last panel, you will still have access to all the previously filled-out controls.
您可以设计多步骤注册过程,而无需使用会话存储或使用数据库存储临时数据。您可以设计一个.aspx页面,其中包含多个面板,您可以一次看到一个面板。当用户完成最后一个面板时,您仍然可以访问所有以前填写的控件。