如何通过IP,cookie和会话ID了解网站用户是否处于活动状态 [英] how do I know if a user of website is active by IP, cookie and Session ID

查看:216
本文介绍了如何通过IP,cookie和会话ID了解网站用户是否处于活动状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我必须阻止同一用户多次登录我的网站。使用以下功能,我可以检查并阻止同一用户是否尝试使用公共数据表再次登录。

现在处理会话而不按下注销按钮,我们可以检查是否有会话是否基于用户的IP地址和会话ID可以存储在cookie中?



Hi All,

I had to block the same user multi login to my website. With the following function I am able to check and block if the same user tries to login again by using a public datatable.
Now for dealing with sessions ended without pressing logout button, can we check if a session is active based upon a user's IP address, and session ID which may be stored in a cookie?

 Public dtExistingUsers As DataTable


Protected Function fnMultipleUserCheck(ByVal UserID)
        fnMultipleUserCheck = 0

	If IsNothing(dtExistingUsers) Then
            dtExistingUsers = New DataTable
            dtExistingUsers.Columns.Add("Session_UserName")
            dtExistingUsers.Columns.Add("Session_IP")
            dtExistingUsers.Columns.Add("Session_ID")
        End If

	For Each row As DataRow In dtExistingUsers.Rows
            If row.Item("Session_UserName") = UserID Then
                fnMultipleUserCheck = 1
            End If
        Next

	If fnMultipleUserCheck = 0 Then
	    Dim newrow As DataRow = dtExistingUsers.NewRow
            newrow.Item("Session_UserName") = UserID
            newrow.Item("Session_IP") = System.Web.HttpContext.Current.Request.UserHostAddress
            newrow.Item("Session_ID") = HttpContext.Current.Session.SessionID
            dtExistingUsers.Rows.Add(newrow)
	End If

	 Return fnMultipleUserCheck
    End Function





谢谢



Thanks

推荐答案

网络是无国籍的,网站不知道谁与其连接或者来自哪里,或者谁是活跃的。接受和接受这个概念比试图使其成为有状态更好,在你尝试过之前很多都失败了。让人们根据需要多次登录,不依赖会话结束事件,不关心谁是活跃的,谁不关心。
The web is stateless, a website doesn't know who is "connected" to it or where from, or who is "active". It is better to accept and go with that concept than trying to make it stateful, which many before you have tried and all have failed. Let people log in as many times as they want and don't rely on session end events, don't care about who is active and who isn't.


这篇关于如何通过IP,cookie和会话ID了解网站用户是否处于活动状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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