我可以为指定的Session变量设置会话超时,而不是其他会话变量

时间:2022-08-24 15:53:36

I'd like to set the timeout on a specific Session Variable in a .Net web application, but leave other Session variables alone. Is this possible?

我想在.Net Web应用程序中的特定会话变量上设置超时,但只保留其他Session变量。这可能吗?

Example:

I have 5 Session Variables

我有5个会话变量

Session(var1) Session(var2) Session(var3) Session(var4) Session(var5)

会话(var1)会话(var2)会话(var3)会话(var4)会话(var5)

I want to set it so that Session(var1) through Session(var4) have a timeout of 8 hours (480 minutes), but Session(var5) has a timeout of 20 minutes. Can it be done?

我想设置它以使Session(var1)到Session(var4)的超时时间为8小时(480分钟),但Session(var5)的超时时间为20分钟。可以吗?

3 个解决方案

#1


You may implement this feature by creating timestamp field in this variable (or associated timestamp field). The timestamp will mark the time after which the variable becomes invalid. Of course you will have to handle the timestamp manually in your code (update it per hit, and remove it from session when it becomes invalid).

您可以通过在此变量(或关联的时间戳字段)中创建时间戳字段来实现此功能。时间戳将标记变量变为无效的时间。当然,您必须在代码中手动处理时间戳(每次点击更新它,并在会话失效时将其从会话中删除)。

#2


You would need to use an alternative to Session for storage. The Caching framework of asp.net is probably the closest alternative. Refer to Adding Items to the Cache.

您需要使用Session的替代方法进行存储。 asp.net的缓存框架可能是最接近的选择。请参阅向缓存添加项目。

#3


You could provide your own implementation of HttpSessionStateBase your version would be aware of the different things it can store and change when they are flushed from the session.

您可以提供自己的HttpSessionStateBase实现,您的版本将知道它们可以存储的不同内容以及从会话中刷新它们时的更改。

#1


You may implement this feature by creating timestamp field in this variable (or associated timestamp field). The timestamp will mark the time after which the variable becomes invalid. Of course you will have to handle the timestamp manually in your code (update it per hit, and remove it from session when it becomes invalid).

您可以通过在此变量(或关联的时间戳字段)中创建时间戳字段来实现此功能。时间戳将标记变量变为无效的时间。当然,您必须在代码中手动处理时间戳(每次点击更新它,并在会话失效时将其从会话中删除)。

#2


You would need to use an alternative to Session for storage. The Caching framework of asp.net is probably the closest alternative. Refer to Adding Items to the Cache.

您需要使用Session的替代方法进行存储。 asp.net的缓存框架可能是最接近的选择。请参阅向缓存添加项目。

#3


You could provide your own implementation of HttpSessionStateBase your version would be aware of the different things it can store and change when they are flushed from the session.

您可以提供自己的HttpSessionStateBase实现,您的版本将知道它们可以存储的不同内容以及从会话中刷新它们时的更改。