在asp.net applcation中同时停止用户多次登录。 [英] To stop multiple logins by a user at the same time in asp.net applcation.

查看:85
本文介绍了在asp.net applcation中同时停止用户多次登录。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在我的asp.net应用程序中为每个用户维护一个会话,即同时停止单个用户的多次登录。

对此最好的解决方案是什么?请帮忙。

I have to maintain one session per user in my asp.net application i.e. to stop multiple logins by a single user at the same time.
What is the best solution for this? Please help.

推荐答案

private List<string> getOnlineUsers()
    {
        List<string> activeSessions = new List<string>();
        object obj = typeof(HttpRuntime).GetProperty("CacheInternal", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null, null);
        object[] obj2 = (object[])obj.GetType().GetField("_caches", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(obj);
        for (int i = 0; i < obj2.Length; i++)
        {
            Hashtable c2 = (Hashtable)obj2[i].GetType().GetField("_entries", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(obj2[i]);
            foreach (DictionaryEntry entry in c2)
            {
                object o1 = entry.Value.GetType().GetProperty("Value", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(entry.Value, null);
                if (o1.GetType().ToString() == "System.Web.SessionState.InProcSessionState")
                {
                    SessionStateItemCollection sess = (SessionStateItemCollection)o1.GetType().GetField("_sessionItems", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(o1);
                    if (sess != null)
                    {
                        if (sess["loggedInUserId"] != null)
                        {
                            activeSessions.Add(sess["loggedInUserId"].ToString());
                        }
                    }
                }
            }
        }
        return activeSessions;
    }</string></string></string>





使用此功能可以获取所有活动会话的列表,因此当用户登录时尝试检查,用户已经在是不是清单。



参考:

http://stackoverflow.com/questions/8854176/get-a-list-of-全部活动会话在asp网络中[ ^ ]


您好,



你可以试试这个参考:

大多数用户使用/实现这个逻辑来达到同样的目的: http://stackoverflow.com/questions/2599118/in-asp-net-site-how-to-prevent-multiple- logins-of-same-user-id [ ^ ]



通过ASP.NET中的单个用户ID防止同时登录 [ ^ ]



http://www.webdbtips.com/147867/ [< a href =http://www.webdbtips.com/147867/target =_ blanktitle =新窗口> ^ ]



http://forums.asp。 net / t / 1752144.aspx / 1 [ ^ ]
Hi,

you can try this refrences:
Most of the user use/implement this logic to achieve the same: http://stackoverflow.com/questions/2599118/in-asp-net-site-how-to-prevent-multiple-logins-of-same-user-id[^]

Prevent Simultaneous Logins by a Single User ID in ASP.NET[^]

http://www.webdbtips.com/147867/[^]

http://forums.asp.net/t/1752144.aspx/1[^]






没有配置设置,你必须自己构建它。

您需要维护登录用户的全局列表。如果有人尝试

登录,请检查此列表并显示已登录

消息。

您需要添加代码到Session_End事件处理程序,如果他们的会话到期时(当他们刚刚离开网站/关闭他们的b $ b他们的浏览器而不是退出时)从该列表中删除

用户。 />


小心:有浏览器崩溃的用户无法退出,

现在需要等待20分钟才能访问你的网站了!

您的用户在某个会话中登录他/她无法注销的事实

,不一定是他/她错误!



问候,

Nirav Prabtani。
Hi,

There is no "configuration setting" for this, you have to build it yourself.
You need to maintain a global list of "logged in users". If someone tries
to log in, check against this list and display a "already logged in"
message.
You need to add code to the Session_End event handler to remove
users from this list if their session expires (when they just left the site/closed
their browser instead of logging out).

Be careful: users that had a browser-crash that prevented them from logging out,
now need to wait 20 minutes before they can access your site again!
The fact that your user is logged in in some session that he/she can't log out
of, doesn't have to be his/her fault!

Regards ,
Nirav Prabtani.


这篇关于在asp.net applcation中同时停止用户多次登录。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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