简体   繁体   English

如何从Unique sessionID中终止会话?

[英]How to kill the session from Unique sessionID?

I have count the number of online user to the web server. 我已经计算了Web服务器的在线用户数。 I have created the username & assign the password to individual computer then using this user name user can access the main page & after login user I have add the username, session ID, IP address in datatable. 我已经创建了用户名并为每个计算机分配了密码,然后使用该用户名用户可以访问主页,并在登录用户后在数据表中添加了用户名,会话ID和IP地址。 If i user already connected from another computer then same user access the information from another computer then user first disconnect the already connected from current computer using kill the session from sessionID . 如果我的用户已经从另一台计算机连接,那么同一用户从另一台计算机访问信息,则用户首先使用kill session from sessionID断开已连接的计算机与当前计算机的连接。 then another computer functionality automatically disabled to user then user can start the new session for current computer. 然后自动为用户禁用另一台计算机功能,然后用户可以为当前计算机启动新会话。

How to kill the session from Unique sessionID & disabled the all functionality of the another computer user? 如何从唯一会话ID中终止会话并禁用另一台计算机用户的所有功能?

i would try it this way : On login generate a random string, write it into a session variable and store it in database, then in ur page compare this values against each other to verify user access. 我会这样尝试:登录时生成一个随机字符串,将其写入会话变量并将其存储在数据库中,然后在我们的页面中将这些值相互比较以验证用户访问权限。 this way a user can be logged on only once. 这样,用户只能登录一次。

您可以使用以下代码:

Session.Remove("keyOfSession");

For example you could have a property object in your ApplicationInstance, such as a Dictionary : 例如,您可以在ApplicationInstance中有一个属性对象,例如Dictionary:

  • Key would be the userId 密钥将是userId
  • Value would be a list of KeyValuePair where 值将是KeyValuePair的列表,其中
    • KVP Key would be user IP KVP密钥将是用户IP
    • KVP Value would be a WeakReference to a session object KVP值将是对会话对象的WeakReference

At the end of a Session_Start, you insert an item in your Dictionary=>List for the corresponding user and IP holding a WeakReference to the Session object. 在Session_Start的末尾,您可以在Dictionary => List中为对应的用户和IP插入一个项目,该IP持有对Session对象的WeakReference。 Then, you also End() all other not null, weak referenced, Session objects for this user and other IPs (be aware that some users access the internet through dynamic proxies that may change between requests) 然后,还为该用户和其他IP终止()所有其他非空,弱引用的Session对象(请注意,某些用户通过动态代理访问Internet,这些代理可能在请求之间发生变化)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM