我怎么知道哪些用户的会话ID已经过期(以及用户是否在线?) [英] How do I know which user's session id has been expired (and which users are online?)

查看:152
本文介绍了我怎么知道哪些用户的会话ID已经过期(以及用户是否在线?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个在线国际象棋游戏。在用户presses登录按钮,我省用户ID 在会话变量:

I am developing an online chess game. After a user presses the login button, I save userid in a session variable:

     Session["userID"] = userId.Text;

分配变量之后,用户被转移到另一页。

After assigning the variable, the user is transferred to another page.

有一种可能性,不止一个用户同时在线。让我们说三个用户在线的时间和在会话变量一个用户包含1的用户id,旁边包含2,依此类推。

There is a possibility more then one user is online at a time. Let say three user are online at a time and in session variable one user contain "1" userId, next contain "2" and so on.

如果该用户的会话ID之一到期出于某种原因,我怎么知道哪些用户的会话过期?

If one of the user's Session Id expires for some reason, how do I know which user's session expired?

的原因是我想说明的其他用户,这个特殊的用户不在线了。

The reason is I want to show the other users that this particular user is not online anymore.

推荐答案

会话数据意味着是私人用户,并不意味着要你的应用程序的其他部分访问(即,用户的上下文之外)。这意味着,做你想要使用会话什么将是艰苦和尴尬。

Session data is meant to be private to the user and is not meant to be accessible to the rest of your application (that is, outside the user's context). That means that doing what you want using the session is going to be hard and awkward.

有一个更好的替代方法是跟踪用户活动在一个单独的数据结构,并保持在Web服务器的内存(使用静态变量或System.Web.Caching命名空间),或在数据库中。

A better alternative would be to track user activity in a separate datastructure and keep that in the web server's memory (using a static variable or the System.Web.Caching namespace) or in the database.

这篇关于我怎么知道哪些用户的会话ID已经过期(以及用户是否在线?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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