示例#1
0
        protected bool AuthorizeIs(HttpContextBase httpContext)
        {
            Hashtable userOnline = (Hashtable)httpContext.Application["Online"];

            if (userOnline != null)
            {
                var ide = userOnline.GetEnumerator();
                if (userOnline.Count > 0)
                {
                    while (ide.MoveNext())
                    {
                        //判断登录时保存的Session是否与现在的Session相同
                        if (userOnline.Contains(httpContext.Session.SessionID))
                        {
                            if (ide.Key != null && ide.Key.ToString() == httpContext.Session.SessionID)
                            {
                                if (ide.Value != null && ide.Value == "-1")
                                { //说明该帐户已经被人重复登录
                                    //把当前的这个Session所对应的用户”踢出“
                                    userOnline.Remove(httpContext.Session.SessionID);
                                    httpContext.Application.Lock();
                                    httpContext.Application["Online"] = userOnline;
                                    httpContext.Application.UnLock();
                                    //httpContext.Response.Redirect("/Account/LogOn?SSO=1", true);
                                    return(false);
                                }
                            }
                        }
                        else
                        {
                            RecordLog.RecordInfo("httpContext.Session.SessionID:" + httpContext.Session.SessionID + "-userOnline:" + userOnline.Count);
                            return(false);
                        }
                    }
                }
                else
                {
                    RecordLog.RecordInfo("userOnline:" + userOnline.Count);
                    return(false);
                }
            }

            return(true);

            //return base.AuthorizeCore(httpContext);
        }