///登录页面
Hashtable haol = (Hashtable)Application["olTable"];
if (haol == null)
{
haol = new Hashtable();
Application["olTable"] = haol;
}
else
{ HttpCookie cookie = new HttpCookie("ZInfo");//定义cookie对象以及名为Info的项  
if (Request.Cookies["Info"] != null)
{
Request.Cookies["Info"].Values["UserHotleID"] = SessionInclude.UserBranchId;
//cookie.Values.Add("UserHotleID", SessionInclude.UserBranchId);
Response.AppendCookie(cookie);//确定写入cookie中 
}
else
{
cookie.Values.Add("UserHotleID", SessionInclude.UserBranchId);
Response.AppendCookie(cookie);//确定写入cookie中 
} //当前用户标识
Guid key = Guid.NewGuid();
Session["userKey"] = key;
IDictionaryEnumerator list = haol.GetEnumerator();
ArrayList ls = new ArrayList();
while (list.MoveNext())
{
if (list.Value.ToString() == SessionInclude.SessionId.Trim())
{
ls.Add(list.Key);
//haol.Remove(list.Key);
}
}
int i = ls.Count - ;
while (i > -)
{
Application.Lock();
haol.Remove(ls[i]);
Application.UnLock();
i = i - ;
}
Application.Lock();
haol.Add(key, SessionInclude.SessionId.Trim());
Application["olTable"] = haol;
Application.UnLock();
}
   ///所有页面继承类
public class BasePage : System.Web.UI.Page
{
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
} override protected void OnInit(EventArgs e)
{
BasePageInitInfo();
}
public void BasePageInitInfo()
{
try
{
Hashtable haol = (Hashtable)Application["olTable"];
if (haol == null)
{
haol = new Hashtable();
Application["olTable"] = haol;
}
else
{
if (Session["userKey"] != null)
{
//当前用户Key
Guid key = new Guid(Session["userKey"].ToString());
IDictionaryEnumerator val = haol.GetEnumerator();
while (val.MoveNext())
{
if (val.Value.ToString().Trim() == SessionInclude.SessionId.Trim())
{
Guid currGuid = new Guid(val.Key.ToString());
if (!currGuid.Equals(key))
{
Application.Lock();
haol.Remove(Session["userKey"].ToString());
Session["userKey"] = null;
Application.UnLock();
Response.Write("<script>alert('您的帐号在别处登录,您被迫下线');window.parent.location='../Login.aspx';</script>");
break;
}
}
}
}
else
{
//当前用户标识
Guid key = Guid.NewGuid();
Session["userKey"] = key;
IDictionaryEnumerator list = haol.GetEnumerator();
ArrayList ls = new ArrayList();
while (list.MoveNext())
{
if (list.Value.ToString() == SessionInclude.SessionId.Trim())
{
ls.Add(list.Key);
//haol.Remove(list.Key);
}
}
int i = ls.Count - ;
while (i > -)
{
Application.Lock();
haol.Remove(ls[i]);
Application.UnLock();
i = i - ;
}
Application.Lock();
haol.Add(key, SessionInclude.SessionId.Trim());
Application["olTable"] = haol;
Application.UnLock();
}
}
}
catch
{ } }

限制帐号同时两处以上登录-ASP.NET的更多相关文章

  1. dedecms--二次开发文章内容页未登录禁止访问和同一个帐号只允许一个ip登录

    最近在用dedecms二次开发会员功能,领导要求,会员未登录不允许访问文章内容页,和同一个账号只允许一个ip登录,我是将这两个在一起判断的,判断session存不存在,不存在的情况下就是未登录,这时候 ...

  2. Putty使用帐号和密码的自动登录

    Putty使用ssh key做验证登陆是最方便的,不用密码.如果不想做key exchange,只是单纯想保存帐号密码做自动登陆,可以借助bat文件的方式如下,其中MyServer是已经保存了的ses ...

  3. djagno重写authenticate实现帐号和邮箱的多方式登录。

    1.在users应用的view中重写authenticate: from django.contrib.auth.backends import ModelBackend from django.db ...

  4. U14Linux的帐号与用户组

    1.在/etc/group和/etc/gshadow中查找mousegroup: grep mousegroup /etc/group /etc/gshadow (grep的使用) 2.其实Linux ...

  5. Git管理多个SSH密钥,Git多帐号配置

    版权声明:转载须标明本文转自严振杰的博客 https://blog.csdn.net/yanzhenjie1003/article/details/69487932版权声明:转载必须注明本文转自严振杰 ...

  6. GitHub两种上传方式的对比----SSH / https

    https://www.jianshu.com/p/1ac06bcd8ab5 https://www.cnblogs.com/lqfxyy/p/5740720.html https://blog.cs ...

  7. SSH简介及两种远程登录的方法

    出处 https://blog.csdn.net/li528405176/article/details/82810342 目录 SSH的安全机制 SSH的安装 启动服务器的SSH服务 SSH两种级别 ...

  8. 如何修改SharePoint2013服务器场帐号密码

    服务器远程登录帐号密码修改密码后,如何修改sharepoint服务器场管理员账户密码,今天登录了一下N久以前的搭建sharepoint2013服务器场的一台服务器器,登录进去以后直接提示帐号密码过期需 ...

  9. 开发Chrome Extension截取你微博的帐号密码

    Google允许开发者对Chrome浏览器做扩展,所以有了之前火爆的12306抢票软件,我 也用它抢过票,一直很好奇它怎么注入js到12306上面的.这周有空研究了下Chrome Extension, ...

随机推荐

  1. hibernate inverse属性的作用

    hibernate配置文件中有这么一个属性inverse,它是用来指定关联的控制方的.inverse属性默认是false,若为false,则关联由自己控制,若为true,则关联由对方控制.见例子: 一 ...

  2. Java 线程同步

    线程同步 1.线程同步的目的是为了保护多个线程访问一个资源时对资源的破坏. 2.线程同步方法是通过锁来实现,每个对象都有切仅有一个锁,这个锁与一个特定的对象关联,线程一旦获取了对象锁,其他访问该对象的 ...

  3. [2016湖南长沙培训Day4][前鬼后鬼的守护 chen] (动态开点线段树+中位数 or 动规 or 贪心+堆优化)

    题目大意 给定一个长度为n的正整数序列,令修改一个数的代价为修改前后两个数的绝对值之差,求用最小代价将序列转换为不减序列. 其中,n满足小于500000,序列中的正整数小于10^9 题解(引自mzx神 ...

  4. One EEG preprocessing pipeline - EEG-fMRI paradigm

    The preprocessing pipeline of EEG data from EEG-fMRI paradigm differs from that of regular EEG data, ...

  5. JS截取字符串

    使用 substring()或者slice() 函数:split() 功能:使用一个指定的分隔符把一个字符串分割存储到数组例子:str=”jpg|bmp|gif|ico|png”;arr=theStr ...

  6. C#基础系列——多线程的常见用法详解

    前言:前面几节分别介绍了下C#基础技术中的反射.特性.泛型.序列化.扩展方法.Linq to Xml等,这篇跟着来介绍下C#的另一基础技术的使用.最近项目有点紧张,所以准备也不是特别充分.此篇就主要从 ...

  7. Angular指令2

    scope Create a new scope for this directive rather than inheriting the parent scope. controller Crea ...

  8. Asp.Net MVC<八>:View的呈现

    ActionResult 原则上任何类型的响应都可以利用当前的HttpResponse来完成.但是MVC中我们一般将针对请求的响应实现在一个ActionResult对象中. public abstra ...

  9. 【USACO 2.3】Controlling Companies (递推)

    题意:A公司对B公司有控制权的条件是满足下面条件之一:A=B,A对B的股份超过50%,A控制的公司对B的股份之和超过50%. 分析:我把控制关系分个等级:第一级是直接的股份超过50%,第二级是至少需要 ...

  10. JQurey

    jQuery 是一个 JavaScript 库.极大地简化了 JavaScript 编程,很容易学习. jQuery 是一个 JavaScript 函数库. jQuery 库包含以下特性: HTML ...